From 875787ab4aebc2f9a96393c7bf3f509559bdd346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 14 Oct 2013 09:02:47 +0000 Subject: [PATCH] Add title bar and message dialog review1133002 --- src/common.js | 56 +++++++++++++ src/model.js | 9 +++ src/sao.less | 22 ++++++ src/screen.js | 17 ++-- src/tab.js | 212 ++++++++++++++++++++++++++++++++++++++++++++------ 5 files changed, 289 insertions(+), 27 deletions(-) diff --git a/src/common.js b/src/common.js index b0af48f51c..598903ed20 100644 --- a/src/common.js +++ b/src/common.js @@ -1684,4 +1684,60 @@ }); Sao.common.ICONFACTORY = new Sao.common.IconFactory(); + + Sao.common.UniqueDialog = Sao.class_(Object, { + init: function() { + this.running = false; + }, + build_dialog: function() { + }, + run: function() { + if (this.running) { + return; + } + var args = Array.slice(arguments); + var prm = jQuery.Deferred(); + args.push(prm); + var dialog = this.build_dialog.apply(this, args); + this.running = true; + dialog.dialog('open'); + return prm; + }, + close: function(dialog) { + dialog.dialog('close'); + this.running = false; + } + }); + + Sao.common.MessageDialog = Sao.class_(Sao.common.UniqueDialog, { + class_: 'message-dialog', + build_dialog: function(message, icon, prm) { + var dialog = jQuery('
', { + 'class': this.class_ + }); + dialog.append(jQuery('

') + .text(message) + .prepend(jQuery('', { + 'class': 'dialog-icon' + }).append(jQuery('', { + 'class': 'ui-icon ' + icon + })))); + dialog.dialog({ + modal: true, + autoOpen: false, + buttons: { + 'OK': function() { + this.close(dialog); + prm.resolve('ok'); + }.bind(this) + } + }); + return dialog; + }, + run: function(message, icon) { + Sao.common.MessageDialog._super.run.call( + this, message, icon || 'ui-icon-info'); + } + }); + Sao.common.message = new Sao.common.MessageDialog(); }()); diff --git a/src/model.js b/src/model.js index 2ac6691a0b..5787abc26c 100644 --- a/src/model.js +++ b/src/model.js @@ -57,6 +57,15 @@ }); // TODO reload ids return this.execute('delete', [record_ids], context); + }, + copy: function(records, context) { + if (jQuery.isEmptyObject(records)) { + return jQuery.when(); + } + var record_ids = records.map(function(record) { + return record.id; + }); + return this.execute('copy', [record_ids, {}], context); } }); diff --git a/src/sao.less b/src/sao.less index ae0d6a2e02..54468831ea 100644 --- a/src/sao.less +++ b/src/sao.less @@ -31,6 +31,18 @@ body { padding: @medium-padding @small-padding; } +.tab-title-bar { + padding: @medium-padding @medium-padding; +} + +.tab-title .ui-button-text { + font-size: @large-font-size; +} + +.tab-status, .tab-info { + float: right; +} + .treeview { & > table.tree { width: 100%; @@ -110,3 +122,13 @@ button { background-size: 16px 16px; } } + +.message-dialog { + & .dialog-icon { + display: table-cell; + } + & p { + display: table; + white-space: pre; + } +} diff --git a/src/screen.js b/src/screen.js index 448a4959e6..69f7294dfd 100644 --- a/src/screen.js +++ b/src/screen.js @@ -491,7 +491,6 @@ }); }, remove: function(delete_, remove, force_remove) { - var result = jQuery.Deferred(); var records = null; if ((this.current_view.view_type == 'form') && this.current_record) { @@ -507,7 +506,7 @@ // TODO delete children before parent prm = this.model.delete_(records); } - prm.done(function() { + return prm.then(function() { records.forEach(function(record) { record.group.remove(record, remove, true, force_remove); }); @@ -531,12 +530,20 @@ // TODO set current_record this.set_current_record(null); // TODO set_cursor - jQuery.when.apply(jQuery, prms).done(function() { + return jQuery.when.apply(jQuery, prms).then(function() { this.display(); - result.resolve(); }.bind(this)); }.bind(this)); - return result; + }, + copy: function() { + var records = this.current_view.selected_records(); + return this.model.copy(records, this.context).then(function(new_ids) { + this.group.load(new_ids); + if (!jQuery.isEmptyObject(new_ids)) { + this.set_current_record(this.group.get(new_ids[0])); + } + this.display(); + }.bind(this)); }, search_active: function(active) { if (active && !this.group.parent) { diff --git a/src/tab.js b/src/tab.js index 3dffbb2dd1..ed4fd2ef1f 100644 --- a/src/tab.js +++ b/src/tab.js @@ -7,6 +7,78 @@ init: function() { this.buttons = {}; }, + create_tabcontent: function() { + this.el = jQuery('

', { + 'class': this.class_ + }); + + var title = this.make_title_bar(); + this.el.append(title); + + var toolbar = this.create_toolbar(); + this.el.append(toolbar); + }, + make_title_bar: function() { + var title = jQuery('
', { + 'class': 'tab-title-bar ui-widget-header ui-corner-all' + }); + + var menu = this.set_menu(); + title.append(menu); + title.append(jQuery('