diff options
| author | Thibault Delavallée <tde@openerp.com> | 2012-06-21 10:16:13 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2012-06-21 10:16:13 +0200 |
| commit | cefce78cb664e1285dfcabe3702bc5aa1b40925f (patch) | |
| tree | 59215bfe4b4a06c0858890c4eaa345310201ef3d /addons/web/static/src/js | |
| parent | 896fd9fdf90470b84b106e6c76463966f39afc9d (diff) | |
| parent | da7c964068ed317f94f2e55624b94388583c861c (diff) | |
[MERGE] Merged with main web.
bzr revid: tde@openerp.com-20120611083449-fjcy5injx0wydrlm
bzr revid: tde@openerp.com-20120612074745-zmfq9i0h3gcqz2z1
bzr revid: tde@openerp.com-20120613153033-8yhiis0mk7a91rfu
bzr revid: tde@openerp.com-20120614083859-eo4gpuvxuqhw9ob1
bzr revid: tde@openerp.com-20120615081833-tyv0wl56wcppwstp
bzr revid: tde@openerp.com-20120618075747-tvealk8do8h1sigb
bzr revid: tde@openerp.com-20120619073535-rgleb9j9g5xy2xeg
bzr revid: tde@openerp.com-20120620073852-xatt6u4855i5g681
bzr revid: tde@openerp.com-20120621081613-hfu05ia738euiarr
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/boot.js | 5 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome.js | 57 | ||||
| -rw-r--r-- | addons/web/static/src/js/coresetup.js | 38 | ||||
| -rw-r--r-- | addons/web/static/src/js/search.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 118 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_list.js | 1 | ||||
| -rw-r--r-- | addons/web/static/src/js/views.js | 72 |
7 files changed, 193 insertions, 100 deletions
diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index f83dbc97095..86f8077b151 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -54,11 +54,6 @@ openerp.web = function(session) { openerp.web[files[i]](session); } } - session.log = function() { - if (session.connection.debug && window.console) { - console.log.apply(console, arguments); - } - } }; // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 2b0f755f75f..88074525d08 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -9,8 +9,7 @@ instance.web.Notification = instance.web.Widget.extend({ template: 'Notification', init: function() { this._super.apply(this, arguments); - // move to instance.web.notification - instance.notification = this; + instance.web.notification = this; }, start: function() { this._super.apply(this, arguments); @@ -141,7 +140,6 @@ instance.web.Dialog = instance.web.Widget.extend({ } }, on_resized: function() { - //openerp.log("Dialog resized to %d x %d", this.$element.width(), this.$element.height()); }, destroy: function () { this.close(); @@ -208,7 +206,14 @@ instance.web.CrashManager = instance.web.CallbackEnabled.extend({ buttons: buttons }).open(); dialog.$element.html(QWeb.render('CrashManager.error', {session: instance.connection, error: error})); - } + }, + on_javascript_exception: function(exception) { + this.on_traceback({ + type: _t("Client Error"), + message: exception, + data: {debug: ""} + }); + }, }); instance.web.Loading = instance.web.Widget.extend({ @@ -577,10 +582,6 @@ instance.web.Menu = instance.web.Widget.extend({ this.renderElement(); this.limit_entries(); this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this })); - this.$element.on('click', 'a.oe_menu_more_link', function() { - self.$element.find('.oe_menu_more').toggle(); - return false; - }); this.$element.on('click', 'a[data-menu]', this.on_menu_click); this.$secondary_menus.on('click', 'a[data-menu]', this.on_menu_click); // Hide second level submenus @@ -601,16 +602,12 @@ instance.web.Menu = instance.web.Widget.extend({ $index.after($more); $more.find('.oe_menu_more').append($index.next().nextAll()); } - this.do_hide_more(); }, auto_limit_entries: function() { // TODO: auto detect overflow and bind window on resize var width = $(window).width(); return Math.floor(width / 125); }, - do_hide_more: function() { - this.$element.find('.oe_menu_more').hide(); - }, /** * Opens a given menu by id, as if a user had browsed to that menu by hand * except does not trigger any event on the way @@ -708,9 +705,8 @@ instance.web.Menu = instance.web.Widget.extend({ */ on_menu_click: function(ev) { var needaction = !!$(ev.target).filter('div.oe_menu_counter').length; + ev.preventDefault(); this.menu_click($(ev.currentTarget).data('menu'), needaction); - ev.stopPropagation(); - return false; }, }); @@ -723,20 +719,12 @@ instance.web.UserMenu = instance.web.Widget.extend({ start: function() { var self = this; this._super.apply(this, arguments); - $('html').bind('click', function() { - self.$element.find('.oe_dropdown_options').hide(); - }); - this.$element.find('.oe_dropdown_toggle').click(function() { - self.$element.find('.oe_dropdown_options').toggle(); - return false; - }); - this.$element.on('click', '.oe_dropdown_options li a[data-menu]', function() { + this.$element.on('click', '.oe_dropdown_menu li a[data-menu]', function(ev) { + ev.preventDefault(); var f = self['on_menu_' + $(this).data('menu')]; if (f) { f($(this)); } - self.$element.find('.oe_dropdown_options').hide(); - return false; }); }, change_password :function() { @@ -880,6 +868,27 @@ instance.web.WebClient = instance.web.Widget.extend({ this.$element.on('mouseenter', '.oe_systray > div:not([data-tipsy=true])', function() { $(this).attr('data-tipsy', 'true').tipsy().trigger('mouseenter'); }); + this.$element.on('click', '.oe_dropdown_toggle', function(ev) { + var $menu = $(this).find('.oe_dropdown_menu'); + var state = $menu.is('.oe_opened'); + setTimeout(function() { + // Do not alter propagation + $menu.toggleClass('oe_opened', !state); + if (!state) { + // Move $menu if outside window's edge + var doc_width = $(document).width(); + var offset = $menu.offset(); + var menu_width = $menu.width(); + var x = doc_width - offset.left - menu_width - 15; + if (x < 0) { + $menu.offset({ left: offset.left + x }).width(menu_width); + } + } + }, 0); + }); + instance.web.bus.on('click', this, function() { + self.$element.find('.oe_dropdown_menu.oe_opened').removeClass('oe_opened'); + }); }, show_common: function() { var self = this; diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 4defde54a3c..9b40b62e825 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -400,6 +400,29 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess } }); +/** + * Event Bus used to bind events scoped in the current instance + */ +instance.web.bus = new (instance.web.Class.extend(instance.web.EventDispatcherMixin, { + init: function() { + instance.web.EventDispatcherMixin.init.call(this, parent); + var self = this; + // TODO fme: allow user to bind keys for some global actions. + // check gtk bindings + // http://unixpapa.com/js/key.html + _.each('click,dblclick,keydown,keypress,keyup'.split(','), function(evtype) { + $('html').on(evtype, self, function(ev) { + self.trigger(evtype, ev); + }); + }); + _.each('resize,scroll'.split(','), function(evtype) { + $(window).on(evtype, self, function(ev) { + self.trigger(evtype, ev); + }); + }); + } +}))(); + /** OpenERP Translations */ instance.web.TranslationDataBase = instance.web.Class.extend(/** @lends instance.web.TranslationDataBase# */{ /** @@ -597,13 +620,18 @@ instance.web.Reload = instance.web.Widget.extend({ this.menu_id = (params && params.menu_id) || false; }, start: function() { + var l = window.location; + var timestamp = new Date().getTime(); + var search = "?ts=" + timestamp; + if (l.search) { + search = l.search + "&ts=" + timestamp; + } + var hash = l.hash; if (this.menu_id) { - // open the given menu id - var url_without_fragment = window.location.toString().split("#", 1)[0]; - window.location = url_without_fragment + "#menu_id=" + this.menu_id; - } else { - window.location.reload(); + hash = "#menu_id=" + this.menu_id; } + var url = l.protocol + "//" + l.host + l.pathname + search + hash; + window.location = url; } }); diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index f9e737471ae..85521a14651 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1571,7 +1571,7 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({ $filter.remove(); }); }) - .prependTo($filter); + .appendTo($filter); } $filter.unbind('click').click(function () { diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 64381a66218..12651148a0c 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -472,7 +472,7 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. return self.on_processed_onchange(response, processed); } catch(e) { - console.error(e); + instance.webclient.crashmanager.on_javascript_exception(e); return $.Deferred().reject(); } }); @@ -728,7 +728,6 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. if (this.sidebar) { this.sidebar.do_attachement_update(this.dataset, this.datarecord.id); } - //instance.log("The record has been created with id #" + this.datarecord.id); this.reload(); return $.when(_.extend(r, {created: true})).then(success); } @@ -914,6 +913,10 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt }, set_fields_view: function(fvg) { this.fvg = fvg; + this.version = parseFloat(this.fvg.arch.attrs.version); + if (isNaN(this.version)) { + this.version = 6.1; + } }, set_tags_registry: function(tags_registry) { this.tags_registry = tags_registry; @@ -921,6 +924,18 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt set_fields_registry: function(fields_registry) { this.fields_registry = fields_registry; }, + // Backward compatibility tools, current default version: v6.1 + process_version: function() { + if (this.version < 7.0) { + this.$form.find('form:first').wrapInner('<group col="4"/>'); + this.$form.find('page').each(function() { + if (!$(this).parents('field').length) { + $(this).wrapInner('<group col="4"/>'); + } + }); + } + selector = 'form[version!="7.0"] page,form[version!="7.0"]'; + }, render_to: function($target) { var self = this; this.$target = $target; @@ -930,6 +945,8 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt var xml = instance.web.json_node_to_xml(this.fvg.arch); this.$form = $('<div class="oe_form">' + xml + '</div>'); + this.process_version(); + this.fields_to_init = []; this.tags_to_init = []; this.labels = {}; @@ -2526,6 +2543,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten var tip_delay = 200; var tip_duration = 3000; var anyoneLoosesFocus = function() { + var used = false; if (self.floating) { if (self.last_search.length > 0) { if (self.last_search[0][0] != self.get("value")) { @@ -2533,13 +2551,17 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten self.display_value["" + self.last_search[0][0]] = self.last_search[0][1]; self.set({value: self.last_search[0][0]}); } else { + used = true; self.render_value(); } } else { + used = true; self.set({value: false}); + self.render_value(); } + self.floating = false; } - if (! self.get("value")) { + if (used) { tip_def.reject(); untip_def.reject(); tip_def = $.Deferred(); @@ -2586,7 +2608,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten e.preventDefault(); }, html: true, - close: anyoneLoosesFocus, + // disabled to solve a bug, but may cause others + //close: anyoneLoosesFocus, minLength: 0, delay: 0 }); @@ -2724,6 +2747,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ }, start: function() { this._super.apply(this, arguments); + this.$element.addClass('oe_form_field_one2many'); var self = this; @@ -2731,7 +2755,6 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ this.dataset.o2m = this; this.dataset.parent_view = this.view; this.dataset.child_name = this.name; - //this.dataset.child_name = this.dataset.on_change.add_last(function() { self.trigger_on_change(); }); @@ -2763,6 +2786,13 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ modes = !!modes ? modes.split(",") : ["tree"]; var views = []; _.each(modes, function(mode) { + if (! _.include(["list", "tree", "graph", "kanban"], mode)) { + try { + throw new Error(_.str.sprintf("View type '%s' is not supported in One2Many.", mode)); + } catch(e) { + instance.webclient.crashmanager.on_javascript_exception(e) + } + } var view = { view_id: false, view_type: mode == "tree" ? "list" : mode, @@ -2773,9 +2803,11 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ } if(view.view_type === "list") { view.options.selectable = self.multi_selection; + view.options.sortable = false; if (self.get("effective_readonly")) { view.options.addable = null; view.options.deletable = null; + view.options.reorderable = false; } } else if (view.view_type === "form") { if (self.get("effective_readonly")) { @@ -2796,6 +2828,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ this.views = views; this.viewmanager = new instance.web.form.One2ManyViewManager(this, this.dataset, views, {}); + this.viewmanager.$element.addClass("oe_view_manager_one2many"); this.viewmanager.o2m = self; var once = $.Deferred().then(function() { self.init_form_last_update.resolve(); @@ -3260,6 +3293,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ }, start: function() { this._super.apply(this, arguments); + this.$element.addClass('oe_form_field_many2many'); var self = this; @@ -3268,7 +3302,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ this.dataset.on_unlink.add_last(function(ids) { self.dataset_changed(); }); - + this.is_setted.then(function() { self.load_view(); }); @@ -3281,7 +3315,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ }); }); }); - }) + }); }, set_value: function(value_) { value_ = value_ || []; @@ -3303,6 +3337,8 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ 'addable': self.get("effective_readonly") ? null : _t("Add"), 'deletable': self.get("effective_readonly") ? false : true, 'selectable': self.multi_selection, + 'sortable': false, + 'reorderable': false, }); var embedded = (this.field.views || {}).tree; if (embedded) { @@ -3948,13 +3984,22 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.exte instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, { init: function(field_manager, node) { + var self = this; this._super(field_manager, node); - this.iframe = this.element_id + '_iframe'; this.binary_value = false; + this.fileupload_id = _.uniqueId('oe_fileupload'); + $(window).on(this.fileupload_id, function() { + var args = [].slice.call(arguments).slice(1); + self.on_file_uploaded.apply(self, args); + }); + }, + stop: function() { + $(window).off(this.fileupload_id); + this._super.apply(this, arguments); }, initialize_content: function() { this.$element.find('input.oe-binary-file').change(this.on_file_change); - this.$element.find('button.oe-binary-file-save').click(this.on_save_as); + this.$element.find('button.oe_binary_file_save').click(this.on_save_as); this.$element.find('.oe-binary-file-clear').click(this.on_clear); }, human_filesize : function(size) { @@ -3970,8 +4015,8 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend( // TODO: on modern browsers, we could directly read the file locally on client ready to be used on image cropper // http://www.html5rocks.com/tutorials/file/dndfiles/ // http://deepliquid.com/projects/Jcrop/demos.php?demo=handler - window[this.iframe] = this.on_file_uploaded; - if ($(e.target).val() != '') { + + if ($(e.target).val() !== '') { this.$element.find('form.oe-binary-form input[name=session_id]').val(this.session.session_id); this.$element.find('form.oe-binary-form').submit(); this.$element.find('.oe-binary-progress').show(); @@ -3979,12 +4024,12 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend( } }, on_file_uploaded: function(size, name, content_type, file_base64) { - delete(window[this.iframe]); if (size === false) { this.do_warn("File Upload", "There was a problem while uploading your file"); // TODO: use openerp web crashmanager console.warn("Error while uploading file : ", name); } else { + this.filename = name; this.on_file_uploaded_and_valid.apply(this, arguments); } this.$element.find('.oe-binary-progress').hide(); @@ -3992,20 +4037,33 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend( }, on_file_uploaded_and_valid: function(size, name, content_type, file_base64) { }, - on_save_as: function() { - $.blockUI(); - this.session.get_file({ - url: '/web/binary/saveas_ajax', - data: {data: JSON.stringify({ - model: this.view.dataset.model, - id: (this.view.datarecord.id || ''), - field: this.name, - filename_field: (this.node.attrs.filename || ''), - context: this.view.dataset.get_context() - })}, - complete: $.unblockUI, - error: instance.webclient.crashmanager.on_rpc_error - }); + on_save_as: function(ev) { + var value = this.get('value'); + if (!value) { + this.do_warn(_t("Save As..."), _t("The field is empty, there's nothing to save !")); + ev.stopPropagation(); + } else if (this._dirty_flag) { + var link = this.$('.oe_binary_file_save_data')[0]; + link.download = this.filename || "download.bin"; // Works on only on Google Chrome + //link.target = '_blank'; + link.href = "data:application/octet-stream;base64," + value; + } else { + $.blockUI(); + this.session.get_file({ + url: '/web/binary/saveas_ajax', + data: {data: JSON.stringify({ + model: this.view.dataset.model, + id: (this.view.datarecord.id || ''), + field: this.name, + filename_field: (this.node.attrs.filename || ''), + context: this.view.dataset.get_context() + })}, + complete: $.unblockUI, + error: instance.webclient.crashmanager.on_rpc_error + }); + ev.stopPropagation(); + return false; + } }, on_clear: function() { if (this.get('value') !== false) { @@ -4073,14 +4131,6 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ template: 'FieldBinaryImage', - initialize_content: function() { - this._super(); - if (!this.get("effective_readonly")) { - this.$element.find('.oe_form_field_image_controls').show(); - } else { - this.$element.find('.oe_form_field_image_controls').hide(); - } - }, set_value: function(value_) { this._super.apply(this, arguments); this.render_value(); diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index de73ec21884..a90dabe1b4c 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -364,6 +364,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi } var total = dataset.size(); + this.$pager.toggleClass('oe_list_pager_single_page', (total <= this.limit())); var spager = '-'; if (total) { var range_start = this.page * this.limit() + 1; diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 753e14fa251..95b87e3cd86 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -77,7 +77,14 @@ instance.web.ActionManager = instance.web.Widget.extend({ }); } else if (state.client_action) { this.null_action(); - this.ir_actions_client(state.client_action); + var action = state.client_action; + if(_.isString(action)) { + action = { + tag: action, + params: state, + }; + } + this.ir_actions_client(action); } $.when(action_loaded || null).then(function() { @@ -150,6 +157,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ this.inner_action = action; this.inner_viewmanager = new instance.web.ViewManagerAction(this, action); this.inner_viewmanager.appendTo(this.$element); + this.inner_viewmanager.$element.addClass("oe_view_manager_global"); } }, ir_actions_act_window_close: function (action, on_closed) { @@ -320,7 +328,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ } this.$element - .find('.oe_view_manager_switch a').parent().removeClass('active') + .find('.oe_view_manager_switch a').parent().removeClass('active'); this.$element .find('.oe_view_manager_switch a').filter('[data-view-type="' + view_type + '"]') .parent().addClass('active'); @@ -329,9 +337,12 @@ instance.web.ViewManager = instance.web.Widget.extend({ _.each(_.keys(self.views), function(view_name) { var controller = self.views[view_name].controller; if (controller) { + var container = self.$element.find(".oe_view_manager_view_" + view_name + ":first"); if (view_name === view_type) { + container.show(); controller.do_show(view_options || {}); } else { + container.hide(); controller.do_hide(); } } @@ -696,6 +707,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({ instance.web.Sidebar = instance.web.Widget.extend({ init: function(parent) { + var self = this; this._super(parent); var view = this.getParent(); this.sections = [ @@ -712,19 +724,24 @@ instance.web.Sidebar = instance.web.Widget.extend({ var item = { label: _t("Translate"), callback: view.on_sidebar_translate, title: _t("Technical translation") }; this.items.other.push(item); } + this.fileupload_id = _.uniqueId('oe_fileupload'); + $(window).on(this.fileupload_id, function() { + var args = [].slice.call(arguments).slice(1); + if (args[0] && args[0].error) { + alert(args[0].error); + } else { + self.do_attachement_update(self.dataset, self.model_id); + } + $.unblockUI(); + }); }, start: function() { var self = this; this._super(this); this.redraw(); - this.$element.on('click','.oe_dropdown_toggle',function(event) { - $(this).parent().find('ul').toggle(); - return false; - }); this.$element.on('click','.oe_dropdown_menu li a', function(event) { var section = $(this).data('section'); var index = $(this).data('index'); - $(this).closest('ul').hide(); var item = self.items[section][index]; if (item.callback) { item.callback.apply(self, [item]); @@ -733,16 +750,12 @@ instance.web.Sidebar = instance.web.Widget.extend({ } else if (item.url) { return true; } - return false; + event.preventDefault(); }); - //this.$div.html(QWeb.render('FormView.sidebar.attachments', this)); - //this.$element.find('.oe-binary-file').change(this.on_attachment_changed); - //this.$element.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete); }, redraw: function() { var self = this; self.$element.html(QWeb.render('Sidebar', {widget: self})); - this.$element.find('ul').hide(); // Hides Sidebar sections when item list is empty this.$('.oe_form_dropdown_section').each(function() { @@ -826,6 +839,8 @@ instance.web.Sidebar = instance.web.Widget.extend({ }); }, do_attachement_update: function(dataset, model_id) { + this.dataset = dataset; + this.model_id = model_id; if (!model_id) { this.on_attachments_loaded([]); } else { @@ -837,42 +852,37 @@ instance.web.Sidebar = instance.web.Widget.extend({ on_attachments_loaded: function(attachments) { var self = this; var items = []; - // TODO: preprend: _s + - var prefix = '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=name&id='; + var prefix = this.session.origin + '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=name&id='; _.each(attachments,function(a) { a.label = a.name; if(a.type === "binary") { a.url = prefix + a.id + '&t=' + (new Date().getTime()); } }); - attachments.push( { label: _t("Add..."), callback: self.on_attachment_add } ); self.items['files'] = attachments; self.redraw(); - }, - on_attachment_add: function(e) { - this.$element.find('.oe_sidebar_add').show(); + this.$('.oe_sidebar_add_attachment .oe-binary-file').change(this.on_attachment_changed); + this.$element.find('.oe_sidebar_delete_item').click(this.on_attachment_delete); }, on_attachment_changed: function(e) { - return; - window[this.element_id + '_iframe'] = this.do_update; var $e = $(e.target); - if ($e.val() != '') { + if ($e.val() !== '') { this.$element.find('form.oe-binary-form').submit(); $e.parent().find('input[type=file]').prop('disabled', true); $e.parent().find('button').prop('disabled', true).find('img, span').toggle(); + this.$('.oe_sidebar_add_attachment span').text(_t('Uploading...')); + $.blockUI(); } }, on_attachment_delete: function(e) { - return; - var self = this, $e = $(e.currentTarget); - var name = _.str.trim($e.parent().find('a.oe-sidebar-attachments-link').text()); - if (confirm(_.str.sprintf(_t("Do you really want to delete the attachment %s?"), name))) { - this.rpc('/web/dataset/unlink', { - model: 'ir.attachment', - ids: [parseInt($e.attr('data-id'))] - }, function(r) { - $e.parent().remove(); - self.do_notify("Delete an attachment", "The attachment '" + name + "' has been deleted"); + var self = this; + e.preventDefault(); + e.stopPropagation(); + var self = this; + var $e = $(e.currentTarget); + if (confirm(_t("Do you really want to delete this attachment ?"))) { + (new instance.web.DataSet(this, 'ir.attachment')).unlink([parseInt($e.attr('data-id'), 10)]).then(function() { + self.do_attachement_update(self.dataset, self.model_id); }); } } |
