← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-client-web/save-prompt-action into lp:openobject-client-web

 

vda(Open ERP) has proposed merging lp:~openerp-dev/openobject-client-web/save-prompt-action into lp:openobject-client-web.

Requested reviews:
  OpenERP SA's Web Client R&D (openerp-dev-web)


If user clicks any where out side content area and form view has modified fields, then confirmation message will be raised.
-- 
https://code.launchpad.net/~openerp-dev/openobject-client-web/save-prompt-action/+merge/36822
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-client-web/save-prompt-action.
=== modified file 'addons/openerp/controllers/templates/menu.mako'
--- addons/openerp/controllers/templates/menu.mako	2010-09-20 05:30:59 +0000
+++ addons/openerp/controllers/templates/menu.mako	2010-09-28 07:03:47 +0000
@@ -47,7 +47,7 @@
                 <ul class="sc_menu">
                     %for parent in parents:
                         <li id="${parent['id']}" class="menu_tabs">
-                            <a href="${py.url('/openerp/menu', active=parent['id'])}" target="_top" class="${parent.get('active', '')}">
+                            <a href="javascript: void(0)" target="_top" onclick="navigate_action('${parent['id']}', menu_action)" class="${parent.get('active', '')}">
                                 <span>${parent['name']}</span>
                             </a>
                             <em>[1]</em>

=== modified file 'addons/openerp/static/javascript/form.js'
--- addons/openerp/static/javascript/form.js	2010-09-21 13:10:33 +0000
+++ addons/openerp/static/javascript/form.js	2010-09-28 07:03:47 +0000
@@ -922,10 +922,18 @@
     window.open(openobject.http.getURL(act, params));
 }
 
-function do_action(action_id, field, relation, src, data){
-
+function do_action(src){
+    var $src = jQuery(src);
+    var action_id = $src.attr('action_id');
+    var field = '_terp_id';
+    
+    var relation = $src.attr('relation');
+    var data = $src.attr('data');
+    
     var params = {};
-
+    var domain = $src.attr('domain');
+    var context = $src.attr('context');
+    
     if (openobject.dom.get('_terp_list')) {
         var list = new ListView('_terp_list');
         var ids = list.getSelectedRecords();
@@ -937,12 +945,11 @@
         params['_terp_selection'] = '[' + ids.join(',') + ']';
     }
     
-    var id = openobject.dom.get(field).value;
-    var domain = getNodeAttribute(src, 'domain');
-    var context = getNodeAttribute(src, 'context');
+    var id = jQuery('#'+field).val();
+    var source = jQuery('#'+field).attr('id');
     
     var req = eval_domain_context_request({
-        'source': openobject.dom.get(field).id,
+        'source': source,
         'active_id': id,
         'active_ids': params['_terp_selection'],
         'domain': domain,
@@ -1221,7 +1228,7 @@
 
 
 var is_form_changed = false;
-function validateForm(){
+function validateForm() {
     is_form_changed = false;
     jQuery('#view_form table tr td:first').find('input:not([type=hidden]), select').change(function(){
         is_form_changed = true;
@@ -1238,3 +1245,7 @@
     }
     return get_form_action(action, args)
 }
+
+function menu_action(action_id) {
+    window.location.href = openobject.http.getURL('/openerp/menu', {'active': action_id})
+}

=== modified file 'addons/openerp/static/javascript/openerp/openerp.base.js'
--- addons/openerp/static/javascript/openerp/openerp.base.js	2010-09-27 07:52:12 +0000
+++ addons/openerp/static/javascript/openerp/openerp.base.js	2010-09-28 07:03:47 +0000
@@ -21,6 +21,7 @@
             complete: function () {
                 if(afterLoad) { afterLoad(); }
             },
+            async: false,
             success: doLoadingSuccess(app),
             error: function (xhr, status, error) {
                 if(xhr.status != 500) {
@@ -36,6 +37,35 @@
         window.location.assign(url);
     }
 }
+
+function navigate_action(url) {
+    var perform_action = arguments[1];
+    var afterLoad = arguments[2];
+    if(is_form_changed) {
+        if (confirm('The record has been modified \n Do you want to save it ?')) {
+            var $form = jQuery('#view_form');
+            if (!validate_required($form.get(0))) {
+                if(afterLoad) { afterLoad(); }
+                return;
+            }
+            $form.ajaxSubmit({
+                error: function(xhr, status, error){
+                    displayErrorOverlay(xhr);
+                    if(afterLoad) { afterLoad(); }
+                },
+                success: function(){
+                    perform_action(url, afterLoad);
+                }
+            });
+        } else {
+            perform_action(url, afterLoad);
+        }
+    }
+    else {
+        perform_action(url, afterLoad);
+    }
+    is_form_changed = false;
+}
 /**
  * Displays a fancybox containing the error display
  * @param xhr the received XMLHttpResponse
@@ -95,8 +125,9 @@
         // external links. Ignore hash-links.
         jQuery(document).delegate('a[href]:not([target]):not([href^="#"]):not([href^="javascript"]):not([rel=external])', 'click', function () {
             waitBox.showAfter(LINK_WAIT_NO_ACTIVITY);
-            openLink(jQuery(this).attr('href'),
-                     jQuery.proxy(waitBox, 'hide'));
+            navigate_action(jQuery(this).attr('href'),
+                            openLink,
+                            jQuery.proxy(waitBox, 'hide'));
             return false;
         });
         // do the same for forms
@@ -128,7 +159,7 @@
         if(!newUrl || newUrl == currentUrl) {
             return;
         }
-        openLink(newUrl);
+        navigate_action(newUrl,openLink);
     });
     // if the initially loaded URL had a hash-url inside
     jQuery(window).trigger('hashchange');

=== modified file 'addons/openerp/widgets/templates/sidebar.mako'
--- addons/openerp/widgets/templates/sidebar.mako	2010-09-21 13:10:33 +0000
+++ addons/openerp/widgets/templates/sidebar.mako	2010-09-28 07:03:47 +0000
@@ -1,6 +1,6 @@
 <%def name="sidebox_action_item(item, model, submenu)">
     % if submenu != 1:
-    	<li data="${item}" onclick="do_action(${item['id']}, '_terp_id', '${model}', this, getNodeAttribute(this, 'data'));">
+    	<li data="${item}" action_id="${item['id']}" relation="${model}" onclick="navigate_action(this, do_action)">
     	   <a href="javascript: void(0)" onclick="return false">${item['name']}</a>
         </li>
     % else:


Follow ups