diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2011-04-05 12:17:39 +0200 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2011-04-05 12:17:39 +0200 |
| commit | df3257a741e59accba62d5a73ec7eeaafeb98c7d (patch) | |
| tree | 60d42925bc1b5d4061ce1b216600caf5ecfdfb96 /addons/base/static/src | |
| parent | 26951a725e2881169e828a0ac2775cd7c64caed3 (diff) | |
| parent | 9cccfd135085ce5ac15aa6f19907d6a705c66f62 (diff) | |
[MERGE]
bzr revid: nicolas.vanhoren@openerp.com-20110404160926-f1uwddcknsezvamr
bzr revid: nicolas.vanhoren@openerp.com-20110405101739-iubtgou4lrnftmi2
Diffstat (limited to 'addons/base/static/src')
| -rw-r--r-- | addons/base/static/src/base.html | 1 | ||||
| -rw-r--r-- | addons/base/static/src/css/base.css | 38 | ||||
| -rw-r--r-- | addons/base/static/src/js/chrome.js | 77 | ||||
| -rw-r--r-- | addons/base/static/src/js/data.js | 244 | ||||
| -rw-r--r-- | addons/base/static/src/js/form.js | 170 | ||||
| -rw-r--r-- | addons/base/static/src/js/list.js | 17 | ||||
| -rw-r--r-- | addons/base/static/src/js/views.js | 54 | ||||
| -rw-r--r-- | addons/base/static/src/xml/base.xml | 53 |
8 files changed, 296 insertions, 358 deletions
diff --git a/addons/base/static/src/base.html b/addons/base/static/src/base.html index 7f45085a76d..103e19e25ed 100644 --- a/addons/base/static/src/base.html +++ b/addons/base/static/src/base.html @@ -10,6 +10,7 @@ <script type="text/javascript" src="/base/static/lib/qweb/qweb.js"></script> <script type="text/javascript" src="/base/static/lib/jquery/jquery-1.5.1.js"></script> <script type="text/javascript" src="/base/static/lib/jquery.ui/js/jquery-ui-1.8.9.custom.min.js"></script> + <script type="text/javascript" src="/base/static/lib/jquery.ui/js/jquery-ui-timepicker-addon.js"></script> <script type="text/javascript" src="/base/static/lib/jquery.jqGrid/jquery.jqGrid.js"></script> <script type="text/javascript" src="/base/static/lib/jquery.superfish/js/hoverIntent.js"></script> <script type="text/javascript" src="/base/static/lib/jquery.superfish/js/superfish.js"></script> diff --git a/addons/base/static/src/css/base.css b/addons/base/static/src/css/base.css index 151ec6e214e..82ff0339226 100644 --- a/addons/base/static/src/css/base.css +++ b/addons/base/static/src/css/base.css @@ -12,7 +12,7 @@ body { margin: 2px; } -.#oe_header h2 { +#oe_header h2 { margin: 2px 0; } @@ -68,16 +68,6 @@ body.openerp { width: 100%; height: 100%; } -/* Main Application */ -.openerp .application { - padding: 6px; -} - -.openerp h3.title { - margin: 2px 0; - color: #252424; - text-shadow: white 0 1px 0; -} /* Menu */ .openerp .sf-menu { @@ -305,8 +295,23 @@ body.openerp { text-align: center; } -/* SearchView */ +/* Main Application */ +.openerp .application { + padding: 6px; +} +.openerp h2.oe_view_title { + margin: 2px 0; + color: #252424; + text-shadow: white 0 1px 0; +} + +/* View Manager */ +.openerp .oe_vm_switch { + float: right; +} + +/* SearchView */ .openerp .filter_label, .openerp .filter_icon { border: 1px solid #666; border-left-width: 0; @@ -395,15 +400,14 @@ body.openerp { padding-left: 10px; } -/* View Manager */ -.openerp .views-switchers { - text-align: right; -} /* Form */ .openerp .required.error { border: 1px solid #900; } +.openerp .oe_form_pager { + text-align: right; +} /* Inputs */ .openerp input[type="text"], .openerp input[type="password"], .openerp select, .openerp textarea { @@ -418,7 +422,7 @@ body.openerp { border-radius: 3px; background: white; } -.openerp input.field_date { +.openerp input.field_date, .openerp input.field_datetime { background: url('../img/ui/field_calendar.png') no-repeat right center; background-origin: content-box; -moz-background-origin: content; diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 523f2c8a2b7..bd36b534c85 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -58,11 +58,9 @@ openerp.base.callback = function(obj, method) { * * @class */ -openerp.base.NotFound = Class.extend( - /** @lends openerp.base.NotFound# */ { +openerp.base.NotFound = Class.extend( /** @lends openerp.base.NotFound# */ { }); -openerp.base.KeyNotFound = openerp.base.NotFound.extend( - /** @lends openerp.base.KeyNotFound# */ { +openerp.base.KeyNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.KeyNotFound# */ { /** * Thrown when a key could not be found in a mapping * @@ -77,8 +75,7 @@ openerp.base.KeyNotFound = openerp.base.NotFound.extend( return "The key " + this.key + " was not found"; } }); -openerp.base.ObjectNotFound = openerp.base.NotFound.extend( - /** @lends openerp.base.ObjectNotFound# */ { +openerp.base.ObjectNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.ObjectNotFound# */ { /** * Thrown when an object path does not designate a valid class or object * in the openerp hierarchy. @@ -94,8 +91,7 @@ openerp.base.ObjectNotFound = openerp.base.NotFound.extend( return "Could not find any object of path " + this.path; } }); -openerp.base.Registry = Class.extend( - /** @lends openerp.base.Registry# */ { +openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ { /** * Stores a mapping of arbitrary key (strings) to object paths (as strings * as well). @@ -156,8 +152,7 @@ openerp.base.Registry = Class.extend( } }); -openerp.base.BasicController = Class.extend( - /** @lends openerp.base.BasicController# */{ +openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicController# */{ /** * rpc operations, event binding and callback calling should be done in * start() instead of init so that event can be hooked in between. @@ -198,6 +193,8 @@ openerp.base.BasicController = Class.extend( // try to call deferred methods on this return value. return $.Deferred().done().promise(); }, + on_ready: function() { + }, stop: function() { }, log: function() { @@ -209,25 +206,25 @@ openerp.base.BasicController = Class.extend( this.on_log.apply(this,args); }, on_log: function() { - if(window.console && (window.openerp.debug || (window.location.search.indexOf('?debug') !== -1))) - console.log(arguments); - }, - on_ready: function() { - } -}); + if(true || window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) { + if(window.console) { + console.log(arguments); + } else { + $.each(arguments, function(i,v) { + v = v==null ? "null" : v; + $('<pre></pre>').text(v.toString()).appendTo($('body')); + }); + } + } -openerp.base.Console = openerp.base.BasicController.extend({ - init: function(element_id, server, port) { - this._super(element_id); - } + }, }); -openerp.base.Session = openerp.base.BasicController.extend( - /** @lends openerp.base.Session# */{ +openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.base.Session# */{ /** * @constructs * @extends openerp.base.BasicController - * @param element_id + * @param element_id to use for exception reporting * @param server * @param port */ @@ -249,18 +246,6 @@ openerp.base.Session = openerp.base.BasicController.extend( start: function() { this.session_restore(); }, - on_log: function() { - // TODO this should move to Console and be active only in debug - // TODO $element should be for error not log - var self = this; - this._super.apply(this,arguments); - $.each(arguments, function(i,v) { - if(self.$element) { - v = v==null ? "null" : v; - $('<pre></pre>').text(v.toString()).appendTo(self.$element); - } - }); - }, /** * Executes an RPC call, registering the provided callbacks. * @@ -336,7 +321,6 @@ openerp.base.Session = openerp.base.BasicController.extend( on_rpc_response: function() { }, on_rpc_error: function(error) { - // TODO this should use the $element with focus and button is displaying OPW etc... this.on_log(error.message, error.data.debug); }, /** @@ -386,7 +370,6 @@ openerp.base.Session = openerp.base.BasicController.extend( this.set_cookie('uid', this.uid); this.set_cookie('session_id', this.session_id); }, - // TODO: clear_local /** * Fetches a cookie stored by an openerp session * @@ -446,7 +429,6 @@ openerp.base.Session = openerp.base.BasicController.extend( var self = this; for(var j=0; j<self.module_list.length; j++) { var mod = self.module_list[j]; - self.log("init module "+mod); if(self.module_loaded[mod]) continue; openerp[mod] = {}; @@ -457,12 +439,7 @@ openerp.base.Session = openerp.base.BasicController.extend( } }); -openerp.base.Database = openerp.base.BasicController.extend({ -// Non Session Controller to manage databases -}); - -openerp.base.Controller = openerp.base.BasicController.extend( - /** @lends openerp.base.Controller# */{ +openerp.base.Controller = openerp.base.BasicController.extend( /** @lends openerp.base.Controller# */{ /** * @constructs * @extends openerp.base.BasicController @@ -490,6 +467,16 @@ openerp.base.Controller = openerp.base.BasicController.extend( } }); +openerp.base.CrashManager = openerp.base.Controller.extend({ +// Controller to display exception and stacktrace and eventually report error trought maitenance contract +// if should hook on Session.on_rpc_error: function(error) { +// and display OPW etc... +}); + +openerp.base.Database = openerp.base.Controller.extend({ +// Non Session Controller to manage databases +}); + openerp.base.Loading = openerp.base.Controller.extend({ init: function(session, element_id) { this._super(session, element_id); @@ -686,7 +673,7 @@ openerp.base.WebClient = openerp.base.Controller.extend({ this.menu.start(); }, on_logged: function() { - this.action = new openerp.base.ActionManager(this.session, "oe_application"); + this.action = new openerp.base.ActionManager(this.session, "oe_app"); this.action.start(); }, on_menu_action: function(action) { diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index ad4028fb155..bfee8253abb 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -1,8 +1,7 @@ openerp.base.data = function(openerp) { -openerp.base.DataGroup = openerp.base.Controller.extend( - /** @lends openerp.base.DataGroup# */{ +openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.base.DataGroup# */{ /** * Management interface between views and the collection of selected OpenERP * records (represents the view's state?) @@ -16,10 +15,9 @@ openerp.base.DataGroup = openerp.base.Controller.extend( } }); -openerp.base.DataSet = openerp.base.Controller.extend( - /** @lends openerp.base.DataSet# */{ +openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.DataSet# */{ /** - * Management interface between views and the collection of selected + * DateaManagement interface between views and the collection of selected * OpenERP records (represents the view's state?) * * @constructs @@ -32,13 +30,14 @@ openerp.base.DataSet = openerp.base.Controller.extend( this._super(session); this.model = model; - this._ids = []; - this._active_ids = null; - this._active_id_index = 0; + this.ids = []; + this.offset + this.index = 0; + this.count = 0; - this._sort = []; - this._domain = []; - this._context = {}; + this.sort = []; + this.domain = []; + this.context = {}; }, start: function() { }, @@ -55,141 +54,58 @@ openerp.base.DataSet = openerp.base.Controller.extend( * @param {Number} [limit=null] The maximum number of records to return * @returns itself */ - fetch: function (fields, offset, limit) { + fetch: function (fields, offset, limit, callback) { + var self = this; offset = offset || 0; this.rpc('/base/dataset/find', { model: this.model, fields: fields, - domain: this._domain, - context: this._context, - sort: this._sort, + domain: this.domain, + context: this.context, + sort: this.sort, offset: offset, limit: limit - }, _.bind(function (records) { - var data_records = _.map( - records, function (record) { - return new openerp.base.DataRecord(this.session, this.model, fields, record); - }, this); - - this.on_fetch(data_records, { - offset: offset, - limit: limit, - domain: this._domain, - context: this._context, - sort: this._sort - }); - }, this)); - return this; - }, - /** - * Fires after the DataSet fetched the records matching its internal ids selection - * - * TODO: remove? - * - * @event - * @param {Array} records An array of the DataRecord fetched - * @param event The on_fetch event object - * @param {Number} event.offset the offset with which the original DataSet#fetch call was performed - * @param {Number} event.limit the limit set on the original DataSet#fetch call - * @param {Array} event.domain the domain set on the DataSet before DataSet#fetch was called - * @param {Object} event.context the context set on the DataSet before DataSet#fetch was called - * @param {Array} event.sort the sorting criteria used to get the ids - */ - on_fetch: function (records, event) { - }, - - /** - * Fetch all the currently active records for this DataSet (records selected via DataSet#select) - * - * TODO: add fields, return deferred - * - * @returns itself - */ - active_ids: function (fields) { - this.rpc('/base/dataset/get', { - ids: this.get_active_ids(), - model: this.model - }, _.bind(function (records) { - this.on_active_ids(_.map( - records, function (record) { - return new openerp.base.DataRecord(this.session, this.model, fields, record); - }, this)); - }, this)); - return this; - }, - - /** - * Fires after the DataSet fetched the records matching its internal active ids selection - * - * TODO: remove? - * - * @event - * @param {Array} records An array of the DataRecord fetched - */ - on_active_ids: function (records) { + }, function (records) { + var r = []; + self.offset = offset; + self.count = records.length; // TODO: get real count + for (var i=0; i < records.length; i++ ) { + self.ids.push(records[i].id); + r.push(new openerp.base.DataRecord(self.session, self.model, fields, records[i])); + } + callback(r); + }); }, - - /** - * Fetches the current active record for this DataSet - * - * TODO: add field, return deferred? - * - * @returns itself - */ - active_id: function (fields) { + fetch_ids: function (ids, fields, callback) { this.rpc('/base/dataset/get', { - ids: [this.get_active_id()], - model: this.model - }, _.bind(function (records) { - var record = records[0]; - this.on_active_id( - record && new openerp.base.DataRecord( - this.session, this.model, - fields, record)); - }, this)); - return this; - }, - - /** - * Fires after the DataSet fetched the record matching the current active record - * - * @event - * @param record the record matching the provided id, or null if there is no record for this id - */ - on_active_id: function (record) { - + model: this.model, + ids: ids, + fields: fields + }, function (records) { + var r = []; + for (var i=0; i < records.length; i++ ) { + r.push(new openerp.base.DataRecord(self.session, self.model, fields, records[i])); + } + callback(r); + }); }, - - /** - * Configures the DataSet - * - * @param options DataSet options - * @param {Array} options.domain the domain to assign to this DataSet for filtering - * @param {Object} options.context the context this DataSet should use during its calls - * @param {Array} options.sort the sorting criteria for this DataSet - * @returns itself - */ - set: function (options) { - if (options.domain) { - this._domain = _.clone(options.domain); - } - if (options.context) { - this._context = _.clone(options.context); - } - if (options.sort) { - this._sort = _.clone(options.sort); + fetch_index: function (fields, callback) { + if (_.isEmpty(this.ids)) { + callback([]); + } else { + fields = fields || false; + this.fetch_ids([this.ids[this.index]], fields, callback); } - return this; }, /** * Activates the previous id in the active sequence. If there is no previous id, wraps around to the last one * @returns itself */ - prev: function () { - this._active_id_index -= 1; - if (this._active_id_index < 0) { - this._active_id_index = this._active_ids.length - 1; + previous: function () { + this.index -= 1; + if (this.index < 0) { + this.index = this.ids.length - 1; } return this; }, @@ -199,73 +115,13 @@ openerp.base.DataSet = openerp.base.Controller.extend( * @returns itself */ next: function () { - this._active_id_index += 1; - if (this._active_id_index >= this._active_ids.length) { - this._active_id_index = 0; + this.index += 1; + if (this.index >= this.ids.length) { + this.index = 0; } return this; - }, - - /** - * Sets active_ids by value: - * - * * Activates all ids part of the current selection - * - * * Sets active_id to be the first id of the selection - * - * @param {Array} ids the list of ids to activate - * @returns itself - */ - select: function (ids) { - this._active_ids = ids; - this._active_id_index = 0; - return this; - }, - - /** - * Fetches the ids of the currently selected records, if any. - */ - get_active_ids: function () { - return this._active_ids; - }, - - /** - * Sets the current active_id by value - * - * If there are no active_ids selected, selects the provided id as the sole active_id - * - * If there are ids selected and the provided id is not in them, raise an error - * - * @param {Object} id the id to activate - * @returns itself - */ - activate: function (id) { - if(!this._active_ids) { - this._active_ids = [id]; - this._active_id_index = 0; - } else { - var index = _.indexOf(this._active_ids, id); - if (index == -1) { - throw new Error( - "Could not find id " + id + - " in array [" + this._active_ids.join(', ') + "]"); - } - this._active_id_index = index; - } - return this; - }, - - /** - * Fetches the id of the current active record, if any. - * - * @returns record? record id or <code>null</code> - */ - get_active_id: function () { - if (!this._active_ids) { - return null; - } - return this._active_ids[this._active_id_index]; } + }); openerp.base.DataRecord = openerp.base.Controller.extend({ diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index ea986729d94..245f38279e2 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -2,8 +2,7 @@ openerp.base.form = function (openerp) { openerp.base.views.add('form', 'openerp.base.FormView'); -openerp.base.FormView = openerp.base.Controller.extend( - /** @lends openerp.base.FormView# */{ +openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base.FormView# */{ /** * Indicates that this view is not searchable, and thus that no search * view should be displayed (if there is one active). @@ -22,7 +21,7 @@ openerp.base.FormView = openerp.base.Controller.extend( this.dataset = dataset; this.model = dataset.model; this.view_id = view_id; - this.fields_views = {}; + this.fields_view = {}; this.widgets = {}; this.widgets_counter = 0; this.fields = {}; @@ -36,7 +35,6 @@ openerp.base.FormView = openerp.base.Controller.extend( on_loaded: function(data) { var self = this; this.fields_view = data.fields_view; - //this.log(this.fields_view); var frame = new openerp.base.form.WidgetFrame(this, this.fields_view.arch); @@ -44,31 +42,25 @@ openerp.base.FormView = openerp.base.Controller.extend( _.each(this.widgets, function(w) { w.start(); }); - this.$element.find('button.form_save').click(this.do_save); - -// this.dataset.on_active_id.add(this.on_record_loaded); -// this.dataset.active_id(fields of the form, this.on_record_loaded); - + this.$element.find('div.oe_form_pager button[data-pager-action]').click(function() { + var action = $(this).data('pager-action'); + self.on_pager_action(action); + }); + // sidebar stuff if (this.view_manager.sidebar) this.view_manager.sidebar.load_multi_actions(); }, - on_next: function() { -// this.dataset.next(); -// this.dataset.active_id(fields of the form, this.on_record_loaded); - }, - on_prev: function() { - -// this.dataset.prev(); -// this.dataset.active_id(fields of the form, this.on_record_loaded); - }, on_record_loaded: function(record) { - this.datarecord = record; - for (var f in this.fields) { - this.fields[f].set_value(this.datarecord.values[f]); + if (record.length) { + this.datarecord = record[0]; + for (var f in this.fields) { + this.fields[f].set_value(this.datarecord.values[f]); + } + this.on_form_changed(); + this.ready = true; } - this.on_form_changed(); - this.ready = true; + this.do_update_pager(); }, on_form_changed: function(widget) { for (var w in this.widgets) { @@ -106,11 +98,44 @@ openerp.base.FormView = openerp.base.Controller.extend( // rpc - save.callbacl on_saved } }, + do_show: function () { + this.dataset.fetch_index(this.fields_view.fields, this.on_record_loaded); + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); + }, + do_update_pager: function() { + var $pager = this.$element.find('div.oe_form_pager'); + $pager.find("button[data-pager-action='first'], button[data-pager-action='previous']").attr('disabled', this.dataset.index == 0); + $pager.find("button[data-pager-action='next'], button[data-pager-action='last']").attr('disabled', this.dataset.index == this.dataset.ids.length - 1); + this.$element.find('span.oe_pager_index').html(this.dataset.index + 1); + this.$element.find('span.oe_pager_count').html(this.dataset.count); + }, + on_pager_action: function(action) { + switch (action) { + case 'first': + this.dataset.index = 0; + break; + case 'previous': + this.dataset.previous(); + break; + case 'next': + this.dataset.next(); + break; + case 'last': + this.dataset.index = this.dataset.ids.length - 1; + break; + } + this.dataset.fetch_index(this.fields_view.fields, this.on_record_loaded); + }, on_invalid: function() { }, on_saved: function() { // Check response for exceptions, display error }, + do_search: function (domains, contexts, groupbys) { + }, on_action: function (action) { } }); @@ -119,8 +144,6 @@ openerp.base.FormView = openerp.base.Controller.extend( openerp.base.form = {}; openerp.base.form.Widget = openerp.base.Controller.extend({ - // TODO Change this to init: function(view, node) { and use view.session and a new element_id for the super - // it means that widgets are special controllers init: function(view, node) { this.view = view; this.node = node; @@ -261,22 +284,13 @@ openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({ handle_node: function(n) { var type = this.view.fields_view.fields[n.attrs.name] || {}; var widget_type = n.attrs.widget || type.type || n.tag; - try { - var widget = new (openerp.base.form.widgets.get_object(widget_type)) - (this.view, n); - if (n.tag == 'field' && n.attrs.nolabel != '1') { - var label = new (openerp.base.form.widgets.get_object('label')) - (this.view, n); - label["for"] = widget; - this.add_widget(label); - } - this.add_widget(widget); - } catch (e) { - if (!e instanceof openerp.base.KeyNotFound) { - throw e; - } - this.log("Unhandled widget type : " + widget_type, n); + var widget = new (openerp.base.form.widgets.get_object(widget_type)) (this.view, n); + if (n.tag == 'field' && n.attrs.nolabel != '1') { + var label = new (openerp.base.form.widgets.get_object('label')) (this.view, n); + label["for"] = widget; + this.add_widget(label); } + this.add_widget(widget); }, add_widget: function(w) { if (!w.invisible) { @@ -392,9 +406,8 @@ openerp.base.form.FieldChar = openerp.base.form.Field.extend({ }, set_value: function(value) { this._super.apply(this, arguments); - if (value != null && value !== false) { - this.$element.find('input').val(value); - } + var show_value = (value != null && value !== false) ? value : ''; + this.$element.find('input').val(show_value); }, get_value: function() { }, @@ -429,9 +442,8 @@ openerp.base.form.FieldFloat = openerp.base.form.Field.extend({ }, set_value: function(value) { this._super.apply(this, arguments); - if (value != null && value !== false) { - this.$element.find('input').val(value.toFixed(2)); - } + var show_value = (value != null && value !== false) ? value.toFixed(2) : ''; + this.$element.find('input').val(value); }, get_value: function() { }, @@ -456,9 +468,8 @@ openerp.base.form.FieldText = openerp.base.form.Field.extend({ }, set_value: function(value) { this._super.apply(this, arguments); - if (value != null && value !== false) { - this.$element.find('textarea').val(value); - } + var show_value = (value != null && value !== false) ? value : ''; + this.$element.find('textarea').val(show_value); }, get_value: function() { return this.$element.find('textarea').val(); @@ -486,7 +497,16 @@ openerp.base.form.FieldDate = openerp.base.form.FieldChar.extend({ }, start: function() { this._super.apply(this, arguments); - this.$element.find('input').datepicker(); + this.$element.find('input').datepicker({ + dateFormat: 'yy-mm-dd' + }); + }, + set_value: function(value) { + this._super.apply(this, arguments); + var show_value = (value != null && value !== false) ? value : ''; + this.$element.find('input').val(show_value); + }, + get_value: function() { } }); @@ -494,6 +514,20 @@ openerp.base.form.FieldDatetime = openerp.base.form.FieldChar.extend({ init: function(view, node) { this._super(view, node); this.template = "FieldDatetime"; + }, + start: function() { + this._super.apply(this, arguments); + this.$element.find('input').datetimepicker({ + dateFormat: 'yy-mm-dd', + timeFormat: 'hh:mm:ss' + }); + }, + set_value: function(value) { + this._super.apply(this, arguments); + var show_value = (value != null && value !== false) ? value : ''; + this.$element.find('input').val(show_value); + }, + get_value: function() { } }); @@ -510,6 +544,8 @@ openerp.base.form.FieldSelection = openerp.base.form.Field.extend({ this._super.apply(this, arguments); if (value != null && value !== false) { this.$element.find('select').val(value); + } else { + this.$element.find('select')[0].selectedIndex = 0; } }, get_value: function() { @@ -521,6 +557,11 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({ init: function(view, node) { this._super(view, node); this.template = "FieldMany2One"; + }, + set_value: function(value) { + this._super.apply(this, arguments); + var show_value = (value != null && value !== false) ? value[1] : ''; + this.$element.find('input').val(show_value); } }); @@ -528,6 +569,35 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({ init: function(view, node) { this._super(view, node); this.template = "FieldOne2Many"; + this.viewmanager = null; + this.operations = []; + + }, + start: function() { + this._super.apply(this, arguments); + this.log("o2m.start"); + this.viewmanager = new openerp.base.ViewManager(this.view.session, this.element_id); + var action = { + res_model: this.field.relation, + views: [ [false,"list"], ], + }; + this.viewmanager.do_action_window(action); + + }, + set_value: function(value) { + this.value = value; + this.log("o2m.set_value",value); + }, + get_value: function(value) { + return this.operations; + }, + update_dom: function() { + this._super.apply(this, arguments); + this.$element.toggleClass('disabled', this.readonly); + this.$element.toggleClass('required', this.required); + }, + on_ui_change: function() { + this.view.on_form_changed(this); } }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 7c4deb4e6ec..a4f06cf0d70 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -46,8 +46,7 @@ openerp.base.ListView = openerp.base.Controller.extend({ } } this.dataset.fields = this.cols; - this.dataset.on_fetch.add(this.do_fill_table); - + var width = this.$element.width(); this.$table.jqGrid({ datatype: "local", @@ -82,6 +81,13 @@ openerp.base.ListView = openerp.base.Controller.extend({ })); }, + do_show: function () { + // TODO: re-trigger search + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); + }, do_search: function (domains, contexts, groupbys) { var self = this; this.rpc('/base/session/eval_domain_and_context', { @@ -90,10 +96,9 @@ openerp.base.ListView = openerp.base.Controller.extend({ group_by_seq: groupbys }, function (results) { // TODO: handle non-empty results.group_by with read_group - self.dataset.set({ - context: results.context, - domain: results.domain - }).fetch(self.fields_view.fields, 0, self.limit); + self.dataset.context = results.context; + self.dataset.domain = results.domain; + self.dataset.fetch(self.dataset.fields, 0, self.limit, self.do_fill_table); }); } }); diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js index ad91c28c559..4f4496b89bc 100644 --- a/addons/base/static/src/js/views.js +++ b/addons/base/static/src/js/views.js @@ -31,15 +31,14 @@ openerp.base.ActionManager = openerp.base.Controller.extend({ * Registry for all the main views */ openerp.base.views = new openerp.base.Registry(); + openerp.base.ViewManager = openerp.base.Controller.extend({ - // This will be ViewManager Abstract/Common init: function(session, element_id, desactivate_sidebar) { this._super(session, element_id); this.action = null; this.dataset = null; this.searchview = null; this.active_view = null; - // this.views = { "list": { "view_id":1234, "controller": instance} } this.views = {}; if (desactivate_sidebar) this.sidebar = null; @@ -90,7 +89,11 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ for (var i in this.views) { if (this.views[i].controller) { - this.views[i].controller.$element.toggle(i === view_type); + if (i === view_type) { + this.views[i].controller.do_show(); + } else { + this.views[i].controller.do_hide(); + } } } return view_promise; @@ -123,15 +126,13 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ if (this.searchview) { this.searchview.stop(); } + var view_id = action.search_view_id ? action.search_view_id[0] || false : false; - var searchview = this.searchview = new openerp.base.SearchView( - this, this.session, this.element_id + "_search", - this.dataset, action.search_view_id[0] || false, - this.search_defaults()); - searchview.on_search.add(function() { + this.searchview = new openerp.base.SearchView(this, this.session, this.element_id + "_search", this.dataset, view_id, this.search_defaults()); + this.searchview.on_search.add(function() { self.views[self.active_view].controller.do_search.apply(self, arguments); }); - return searchview.start(); + return this.searchview.start(); }, do_action_window: function(action) { var self = this; @@ -143,7 +144,7 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ var searchview_loaded = this.setup_search_view(action); - this.$element.find('.views-switchers button').click(function() { + this.$element.find('.oe_vm_switch button').click(function() { self.on_mode_switch($(this).data('view-type')); }); _.each(action.views, function(view) { @@ -172,11 +173,11 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ } }); -openerp.base.ViewManagerRoot = openerp.base.Controller.extend({ +openerp.base.ViewManagerRoot = openerp.base.ViewManager.extend({ // Extends view manager }); -openerp.base.ViewManagerUsedAsAMany2One = openerp.base.Controller.extend({ +openerp.base.ViewManagerUsedAsAMany2One = openerp.base.ViewManager.extend({ // Extends view manager }); @@ -314,6 +315,12 @@ openerp.base.CalendarView = openerp.base.Controller.extend({ start: function () { this._super(); this.$element.append('Calendar view'); + }, + do_show: function () { + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); } }); @@ -322,28 +329,43 @@ openerp.base.GanttView = openerp.base.Controller.extend({ start: function () { this._super(); this.$element.append('Gantt view'); + }, + do_show: function () { + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); } }); openerp.base.views.add('tree', 'openerp.base.TreeView'); +openerp.base.TreeView = openerp.base.Controller.extend({ /** * Genuine tree view (the one displayed as a tree, not the list) */ -openerp.base.TreeView = openerp.base.Controller.extend({ start: function () { this._super(); this.$element.append('Tree view'); + }, + do_show: function () { + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); } }); -openerp.base.DiagramView = openerp.base.Controller.extend({ -}); - openerp.base.views.add('graph', 'openerp.base.GraphView'); openerp.base.GraphView = openerp.base.Controller.extend({ start: function () { this._super(); this.$element.append('Graph view'); + }, + do_show: function () { + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); } }); diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index 535d7291c59..7a82ef0447f 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -20,7 +20,7 @@ </td> <td valign="top" width="100%" height="100%"> <div id="oe_main" class="main"> - <div id="oe_application" class="application"></div> + <div id="oe_app" class="application"></div> <div id="oe_sidebar"></div> </div> </td> @@ -32,13 +32,6 @@ </div> </td> </tr> - <tr> - <td colspan="2"> - <div id="oe_errors"> - Debug: - </div> - </td> - </tr> </table> </t> <t t-name="Loading"> @@ -128,18 +121,18 @@ <table class="view-manager-main-table"> <tr> <td class="view-manager-main-content"> - <!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" --> - <div class="views-switchers"> - <t t-foreach="views" t-as="view"> - <button type="button" t-att-data-view-type="view[1]"> - <t t-esc="view[1]"/> - </button> - </t> - </div> - <div t-attf-id="#{prefix}_search"/> + <!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" --> + <div class="oe_vm_switch"> <t t-foreach="views" t-as="view"> - <div t-attf-id="#{prefix}_view_#{view[1]}"/> + <button type="button" t-att-data-view-type="view[1]"> + <t t-esc="view[1]"/> + </button> </t> + </div> + <div t-attf-id="#{prefix}_search"/> + <t t-foreach="views" t-as="view"> + <div t-attf-id="#{prefix}_view_#{view[1]}"/> + </t> </td> <td class="view-manager-main-sidebar"> </td> @@ -160,13 +153,15 @@ <table id="todo_use_unique_id" class="jqGrid"></table> </t> <t t-name="FormView"> - <h3 class="title"><t t-esc="view.fields_view.arch.attrs.string"/></h3> - <div style="text-align:right;"> - <input type="button" value="First"/> - <input type="button" value="<<"/> - 0 / 0 - <input type="button" value=">>"/> - <input type="button" value="Last"/> + <h2 class="oe_view_title"><t t-esc="view.fields_view.arch.attrs.string"/></h2> + <div class="oe_form_pager"> + <button type="button" data-pager-action="first">First</button> + <button type="button" data-pager-action="previous"><<</button> + + <span class="oe_pager_index">0</span> / <span class="oe_pager_count">0</span> + + <button type="button" data-pager-action="next">>></button> + <button type="button" data-pager-action="last">Last</button> </div> <t t-raw="frame.render()"/> <div style="text-align:right;"> @@ -256,10 +251,10 @@ </select> </t> <t t-name="FieldMany2One"> - <input type="text" t-att-name="widget.name" t-att-id="widget.element_id" t-att-class="'field_' + widget.type" style="width: 100%;" placeholder="Many 2 One: Please, enter the ID of the object. Thank you !"/> + <input type="text" t-att-name="widget.name" t-att-id="widget.element_id" t-att-class="'field_' + widget.type" style="width: 100%;"/> </t> <t t-name="FieldOne2Many"> - <div style="background: #ccc; padding: 20px"> + <div t-att-id="widget.element_id"> One2Many widget </div> </t> @@ -281,11 +276,9 @@ </button> </t> <t t-name="SearchView"> - <h3 class="title"><t t-esc="view.attrs['string']"/></h3> - + <h2 class="oe_view_title"><t t-esc="view.attrs['string']"/></h2> <form> <t t-call="SearchView.render_lines"/> - <div style="text-align:right;"> <input type="submit" value="Search"/> <input type="reset" value="Clear"/> |
