Khushboo Bhatt(openerp) has proposed merging
lp:~openerp-dev/openerp-web/trunk-concurrency-kbh into lp:openerp-web.
Requested reviews:
OpenERP R&D Web Team (openerp-dev-web)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-concurrency-kbh/+merge/74993
Add code for concurrency exception in form view.
--
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-concurrency-kbh/+merge/74993
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openerp-web/trunk-concurrency-kbh.
=== modified file 'addons/web/static/src/js/chrome.js'
--- addons/web/static/src/js/chrome.js 2011-09-12 09:32:42 +0000
+++ addons/web/static/src/js/chrome.js 2011-09-12 13:25:53 +0000
@@ -148,6 +148,7 @@
this.close();
},
on_rpc_error: function(error) {
+ var self = this;
this.error = error;
if (error.data.fault_code) {
var split = error.data.fault_code.split('\n')[0].split(' -- ');
@@ -156,7 +157,31 @@
error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
}
}
- if (error.code === 200 && error.type) {
+ if(error.data.fault_code.split('\n')[0] == "ConcurrencyException"){
+ this.dialog_title = "Write concurrency warning ";
+ this.template = 'ConcurrencyException';
+ this.open({
+ width: 'auto',
+ height: 'auto',
+ buttons: {
+ cancle:function(){
+ self.close();
+ },
+ writeanyway:function(){
+ var view_manager = self.widget_parent.action_manager.inner_viewmanager,
+ active_view = view_manager.active_view,
+ view_controller = view_manager.views[active_view].controller,
+ dataset = view_manager.dataset,
+ model = view_controller.model;
+ var key = model.concat(',',dataset.ids[dataset.index].toString());
+ delete view_controller.concurrency_value[key]
+ view_manager.views[active_view].controller.do_save();
+ self.close();
+ }
+ }
+ });
+ }
+ else if (error.code === 200 && error.type) {
this.dialog_title = "OpenERP " + _.capitalize(error.type);
this.template = 'DialogWarning';
this.open({
@@ -171,7 +196,7 @@
height: 'auto'
});
}
- }
+ },
});
openerp.web.Loading = openerp.web.Widget.extend(/** @lends openerp.web.Loading# */{
=== modified file 'addons/web/static/src/js/form.js'
--- addons/web/static/src/js/form.js 2011-09-09 14:34:50 +0000
+++ addons/web/static/src/js/form.js 2011-09-12 13:25:53 +0000
@@ -42,6 +42,7 @@
this.has_been_loaded = $.Deferred();
this.$form_header = null;
this.translatable_fields = [];
+ this.concurrency_value = {};
_.defaults(this.options, {"always_show_new_button": true});
},
start: function() {
@@ -113,7 +114,9 @@
// null index means we should start a new record
promise = this.on_button_new();
} else {
- promise = this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
+ var fields = _.keys(this.fields_view.fields);
+ fields.push("__last_update");
+ promise = this.dataset.read_index(fields, this.on_record_loaded);
}
this.$element.show();
if (this.sidebar) {
@@ -144,6 +147,11 @@
}
this.dirty = false;
this.datarecord = record;
+ if (record.__last_update){
+ var model = this.model;
+ var key = model.concat(',',record.id.toString());
+ this.concurrency_value[key] = record.__last_update;
+ }
for (var f in this.fields) {
var field = this.fields[f];
field.dirty = false;
@@ -353,7 +361,20 @@
self.on_created(r, success, prepend_on_create);
});
} else {
- return this.dataset.write(this.datarecord.id, values, {}, function(r) {
+ var current_model_id = this.model.concat(',',this.datarecord.id);
+ context = {};
+ if (this.concurrency_value) {
+ context["__last_update"] = {};
+ _.each(this.concurrency_value, function(key, value){
+ if (current_model_id == value) {
+ context["__last_update"][value] = key;
+ }
+ });
+ if($.isEmptyObject(context["__last_update"])) {
+ delete context["__last_update"];
+ }
+ }
+ return this.dataset.write(this.datarecord.id, values, {"context":context}, function(r) {
self.on_saved(r, success);
});
}
@@ -442,7 +463,9 @@
if (this.dataset.index == null || this.dataset.index < 0) {
this.on_button_new();
} else {
- this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
+ var fields = _.keys(this.fields_view.fields);
+ fields.push("__last_update");
+ this.dataset.read_index(fields, this.on_record_loaded);
}
},
get_fields_values: function() {
=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml 2011-09-12 13:05:18 +0000
+++ addons/web/static/src/xml/base.xml 2011-09-12 13:25:53 +0000
@@ -1393,6 +1393,21 @@
</p>
</div>
</t>
+
+<t t-name="ConcurrencyException">
+ <table align="left">
+ <tr>
+ <td style="padding: 10px;">
+ <pre>This document has been modified while you were editing it.
+ Choose:
+ - Cancel" to cancel saving.
+ - Write anyway" to save your current version.
+ </pre>
+ </td>
+ </tr>
+ </table>
+</t>
+
<t t-name="FieldStatus">
<div t-att-id="widget.element_id"></div>
</t>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp