From 01e6e3ec079c3221d14903a4a6aa066e0b53dafb Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 17 Jul 2012 15:23:08 +0200 Subject: [PATCH] [IMP] DOWNCASE ALL THE THINGS apparently and contrary to what I remembered, we're still supposed to use underscore_separated method names, not camelCase bzr revid: xmo@openerp.com-20120717132308-wvpldtprt33heee3 --- addons/web/static/src/js/view_form.js | 34 ++--- addons/web/static/src/js/view_list.js | 4 +- .../web/static/src/js/view_list_editable.js | 120 +++++++++--------- addons/web/static/test/list-editable.js | 36 +++--- doc/list-view.rst | 29 ++--- 5 files changed, 110 insertions(+), 113 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 98d50546c52..948b3a73913 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3122,7 +3122,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ } return res; } else if (this.viewmanager.active_view === "list") { - var res = $.when(view.ensureSaved()); + var res = $.when(view.ensure_saved()); if (!res.isResolved() && !res.isRejected()) { console.warn("Asynchronous get_value() is not supported in list view."); } @@ -3209,22 +3209,22 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ this._super(parent, dataset, view_id, _.extend(options || {}, { ListType: instance.web.form.One2ManyList })); - this.on('edit:before', this, this.proxy('_beforeEdit')); - this.on('save:before cancel:before', this, this.proxy('_beforeUnEdit')); + this.on('edit:before', this, this.proxy('_before_edit')); + this.on('save:before cancel:before', this, this.proxy('_before_unedit')); this.records - .bind('add', this.proxy("changedRecords")) - .bind('edit', this.proxy("changedRecords")) - .bind('remove', this.proxy("changedRecords")); + .bind('add', this.proxy("changed_records")) + .bind('edit', this.proxy("changed_records")) + .bind('remove', this.proxy("changed_records")); }, start: function () { var ret = this._super(); this.$element .off('mousedown.handleButtons') - .on('mousedown.handleButtons', 'table button', this.proxy('_buttonDown')); + .on('mousedown.handleButtons', 'table button', this.proxy('_button_down')); return ret; }, - changedRecords: function () { + changed_records: function () { this.o2m.trigger_on_change(); }, is_valid: function () { @@ -3308,21 +3308,21 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ } var parent_form = this.o2m.view; var self = this; - this.ensureSaved().pipe(function () { + this.ensure_saved().pipe(function () { return parent_form.do_save(); }).then(function () { - self.handleButton(name, id, callback); + self.handle_button(name, id, callback); }); }, - _beforeEdit: function () { + _before_edit: function () { this.__ignore_blur = false; - this.editor.form.on('blurred', this, this._onFormBlur); + this.editor.form.on('blurred', this, this._on_form_blur); }, - _beforeUnEdit: function () { - this.editor.form.off('blurred', this, this._onFormBlur); + _before_unedit: function () { + this.editor.form.off('blurred', this, this._on_form_blur); }, - _buttonDown: function () { + _button_down: function () { // If a button is clicked (usually some sort of action button), it's // the button's responsibility to ensure the editable list is in the // correct state -> ignore form blurring @@ -3332,12 +3332,12 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ * Handles blurring of the nested form (saves the currently edited row), * unless the flag to ignore the event is set to ``true`` */ - _onFormBlur: function () { + _on_form_blur: function () { if (this.__ignore_blur) { this.__ignore_blur = false; return; } - this.saveEdition(); + this.save_edition(); }, keyup_ENTER: function () { // blurring caused by hitting the [Return] key, should skip the diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 2bbb9e87866..82c9d1be12b 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -676,7 +676,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi * @param {Function} callback should be called after the action is executed, if non-null */ do_button_action: function (name, id, callback) { - this.handleButton(name, id, callback); + this.handle_button(name, id, callback); }, /** * Base handling of buttons, can be called when overriding do_button_action @@ -688,7 +688,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi * @param {Object} id id of the record the action should be called on * @param {Function} callback should be called after the action is executed, if non-null */ - handleButton: function (name, id, callback) { + handle_button: function (name, id, callback) { var action = _.detect(this.columns, function (field) { return field.name === name; }); diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index bad3f939db2..fa39329fc81 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -12,11 +12,11 @@ openerp.web.list_editable = function (instance) { var self = this; this._super.apply(this, arguments); - this.editor = this.makeEditor(); + this.editor = this.make_editor(); // Stores records of {field, cell}, allows for re-rendering fields // depending on cell state during and after resize events this.fields_for_resize = []; - instance.web.bus.on('resize', this, this.resizeFields); + instance.web.bus.on('resize', this, this.resize_fields); $(this.groups).bind({ 'edit': function (e, id, dataset) { @@ -39,7 +39,7 @@ openerp.web.list_editable = function (instance) { }); }, destroy: function () { - instance.web.bus.off('resize', this, this.resizeFields); + instance.web.bus.off('resize', this, this.resize_fields); this._super(); }, /** @@ -86,7 +86,7 @@ openerp.web.list_editable = function (instance) { if (this.options.editable) { this.$element.find('table:first').show(); this.$element.find('.oe_view_nocontent').remove(); - this.startEdition(); + this.start_edition(); } else { this._super(); } @@ -103,24 +103,24 @@ openerp.web.list_editable = function (instance) { // FIXME: any hook available to ensure this is only done once? this.$buttons .off('click', '.oe_list_save') - .on('click', '.oe_list_save', this.proxy('saveEdition')) + .on('click', '.oe_list_save', this.proxy('save_edition')) .off('click', '.oe_list_discard') .on('click', '.oe_list_discard', function (e) { e.preventDefault(); - self.cancelEdition(); + self.cancel_edition(); }); this.$element .off('click', 'tbody td:not(.oe_list_field_cell)') .on('click', 'tbody td:not(.oe_list_field_cell)', function () { - if (!self.editor.isEditing()) { - self.startEdition(); + if (!self.editor.is_editing()) { + self.start_edition(); } }); // Editor is not restartable due to formview not being // restartable - this.editor = this.makeEditor(); + this.editor = this.make_editor(); var editor_ready = this.editor.prependTo(this.$element) - .then(this.proxy('setupEvents')); + .then(this.proxy('setup_events')); return $.when(result, editor_ready); } @@ -132,13 +132,13 @@ openerp.web.list_editable = function (instance) { * * @return {instance.web.list.Editor} */ - makeEditor: function () { + make_editor: function () { return new instance.web.list.Editor(this); }, do_button_action: function () { var self = this, args = arguments; - this.ensureSaved().then(function () { - self.handleButton.apply(self, args); + this.ensure_saved().then(function () { + self.handle_button.apply(self, args); }); }, /** @@ -149,11 +149,11 @@ openerp.web.list_editable = function (instance) { * * @returns {$.Deferred} */ - ensureSaved: function () { - if (!this.editor.isEditing()) { + ensure_saved: function () { + if (!this.editor.is_editing()) { return $.when(); } - return this.saveEdition(); + return this.save_edition(); }, /** * Set up the edition of a record of the list view "inline" @@ -161,7 +161,7 @@ openerp.web.list_editable = function (instance) { * @param {instance.web.list.Record} [record] record to edit, leave empty to create a new record * @return {jQuery.Deferred} */ - startEdition: function (record) { + start_edition: function (record) { var self = this; var item = false; if (record) { @@ -174,14 +174,14 @@ openerp.web.list_editable = function (instance) { .each(function (field) { attrs[field] = false; }); record = new instance.web.list.Record(attrs); this.records.add(record, { - at: this.isPrependOnCreate() ? 0 : null}); + at: this.prepends_on_create() ? 0 : null}); } - var $recordRow = this.groups.getRowFor(record); - var cells = this.getCellsFor($recordRow); + var $recordRow = this.groups.get_row_for(record); + var cells = this.get_cells_for($recordRow); - return this.ensureSaved().pipe(function () { + return this.ensure_saved().pipe(function () { self.fields_for_resize.splice(0, self.fields_for_resize.length); - return self.withEvent('edit', { + return self.with_event('edit', { record: record.attributes, cancel: false }, function () { @@ -197,13 +197,13 @@ openerp.web.list_editable = function (instance) { self.fields_for_resize.push({field: field, cell: cell}); }).pipe(function () { $recordRow.addClass('oe_edition'); - self.resizeFields(); + self.resize_fields(); return record.attributes; }); }); }); }, - getCellsFor: function ($row) { + get_cells_for: function ($row) { var cells = {}; $row.children('td').each(function (index, el) { cells[el.getAttribute('data-field')] = el @@ -214,11 +214,11 @@ openerp.web.list_editable = function (instance) { * If currently editing a row, resizes all registered form fields based * on the corresponding row cell */ - resizeFields: function () { - if (!this.editor.isEditing()) { return; } + resize_fields: function () { + if (!this.editor.is_editing()) { return; } for(var i=0, len=this.fields_for_resize.length; i jQuery(tr) | null`` has been + * A new method ``get_row_for(record) -> jQuery(tr) | null`` has been added to both ListView.List and ListView.Group, it can be called from the list view to get the table row matching a record (if such a row exists). -* ``ListView#ensure_saved`` has been re-capitalized to - :js:func:`~openerp.web.ListView.ensureSaved` - * :js:func:`~openerp.web.ListView.do_button_action`'s core behavior has been split away to - :js:func:`~openerp.web.ListView.handleButton`. This allows bypassing + :js:func:`~openerp.web.ListView.handle_button`. This allows bypassing overrides of :js:func:`~openerp.web.ListView.do_button_action` in a parent class. - Ideally, :js:func:`~openerp.web.ListView.handleButton` should not be + Ideally, :js:func:`~openerp.web.ListView.handle_button` should not be overridden. * Modifiers handling has been improved (all modifiers information