X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;ds=sidebyside;f=addons%2Fweb_kanban%2Fstatic%2Fsrc%2Fjs%2Fkanban.js;h=b352fb26af962efed3e3113a610d10141cbfc797;hb=f7a76cbb17093784b4e4fc8fdb449819133b18a6;hp=2f3a1d4da1a5f6687cc2fa340e9e2c5182d456cf;hpb=618284c63db7b8a9faf6e5a97f36fb223e5d5c44;p=odoo%2Fodoo.git diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 2f3a1d4..b352fb2 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -43,6 +43,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ this.currently_dragging = {}; this.limit = options.limit || 40; this.add_group_mutex = new $.Mutex(); + this.last_position = 'static'; }, view_loading: function(r) { return this.load_kanban(r); @@ -266,8 +267,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ return false; } self.nb_records = 0; - var remaining = groups.length - 1, - groups_array = []; + var groups_array = []; return $.when.apply(null, _.map(groups, function (group, index) { var def = $.when([]); var dataset = new instance.web.DataSetSearch(self, self.dataset.model, @@ -279,15 +279,15 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ self.nb_records += records.length; self.dataset.ids.push.apply(self.dataset.ids, dataset.ids); groups_array[index] = new instance.web_kanban.KanbanGroup(self, records, group, dataset); - if (!remaining--) { - self.dataset.index = self.dataset.size() ? 0 : null; - return self.do_add_groups(groups_array); - } }); })).then(function () { if(!self.nb_records) { self.no_result(); } + if (self.dataset.index >= self.nb_records){ + self.dataset.index = self.dataset.size() ? 0 : null; + } + return self.do_add_groups(groups_array); }); }); }, @@ -300,6 +300,11 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ self.do_clear_groups(); self.dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit }).done(function(records) { var kgroup = new instance.web_kanban.KanbanGroup(self, records, null, self.dataset); + if (!_.isEmpty(self.dataset.ids) && (self.dataset.index === null || self.dataset.index >= self.dataset.ids.length)) { + self.dataset.index = 0; + } else if (_.isEmpty(self.dataset.ids)){ + self.dataset.index = null; + } self.do_add_groups([kgroup]).done(function() { if (_.isEmpty(records)) { self.no_result(); @@ -350,7 +355,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ var self = this; if (this.group_by) { // Kanban cards drag'n'drop - var prev_widget,is_folded,record; + var prev_widget, is_folded, record; var $columns = this.$el.find('.oe_kanban_column .oe_kanban_column_cards, .oe_kanban_column .oe_kanban_folded_column_cards'); $columns.sortable({ handle : '.oe_kanban_draghandle', @@ -362,7 +367,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ }); record = ui.item.data('widget'); record.$el.bind('mouseup',function(ev,ui){ - if(is_folded)record.$el.hide(); + if (is_folded) { + record.$el.hide(); + } record.$el.unbind('mouseup'); }) ui.placeholder.height(ui.item.height()); @@ -371,7 +378,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ var parent = $(event.target).parent(); prev_widget.highlight(false); is_folded = parent.hasClass('oe_kanban_group_folded'); - if(is_folded){ + if (is_folded) { var widget = parent.data('widget'); widget.highlight(true); prev_widget = widget; @@ -415,8 +422,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ stop: function(event, ui) { var stop_index = ui.item.index(); if (start_index !== stop_index) { - var $start_column = $('.oe_kanban_groups_records .oe_kanban_column').eq(start_index); - var $stop_column = $('.oe_kanban_groups_records .oe_kanban_column').eq(stop_index); + var $start_column = self.$('.oe_kanban_groups_records .oe_kanban_column').eq(start_index); + var $stop_column = self.$('.oe_kanban_groups_records .oe_kanban_column').eq(stop_index); var method = (start_index > stop_index) ? 'insertBefore' : 'insertAfter'; $start_column[method]($stop_column); var tmp_group = self.groups.splice(start_index, 1)[0]; @@ -454,13 +461,13 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ this.dataset.write(record.id, data, {}).done(function() { record.do_reload(); new_group.do_save_sequences(); - if(new_group.state.folded){ + if (new_group.state.folded) { new_group.do_action_toggle_fold(); record.prependTo(new_group.$records.find('.oe_kanban_column_cards')); } }).fail(function(error, evt) { evt.preventDefault(); - alert(_t("An error has occured while moving the record to this group: ") + data.message); + alert(_t("An error has occured while moving the record to this group: ") + error.data.message); self.do_reload(); // TODO: use draggable + sortable in order to cancel the dragging when the rcp fails }); } @@ -493,6 +500,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ || (!this.options.action.help && !this.options.action.get_empty_list_help)) { return; } + this.last_position = this.$el.find('table:first').css("position"); this.$el.find('table:first').css("position", "absolute"); $(QWeb.render('KanbanView.nocontent', { content : this.options.action.get_empty_list_help || this.options.action.help})).insertAfter(this.$('table:first')); this.$el.find('.oe_view_nocontent').click(function() { @@ -500,8 +508,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ }); }, remove_no_result: function() { - this.$el.find('table:first').css("position", false); - this.$el.find('.oe_view_nocontent').remove(); + this.$el.find('table:first').css("position", this.last_position); + this.$el.find('.oe_view_nocontent').remove(); }, /* @@ -575,7 +583,7 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({ } catch(e) {} } _.each(this.view.aggregates, function(value, key) { - self.aggregates[value] = group.get('aggregates')[key]; + self.aggregates[value] = instance.web.format_value(group.get('aggregates')[key], {type: 'float'}); }); } @@ -1096,13 +1104,6 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({ var color = this.kanban_getcolor(variable); return color === '' ? '' : 'oe_kanban_color_' + color; }, - kanban_gravatar: function(email, size) { - size = size || 22; - email = _.str.trim(email || '').toLowerCase(); - var default_ = _.str.isBlank(email) ? 'mm' : 'identicon'; - var email_md5 = $.md5(email); - return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size + '&d=' + default_; - }, kanban_image: function(model, field, id, cache, options) { options = options || {}; var url; @@ -1148,7 +1149,7 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({ */ instance.web_kanban.QuickCreate = instance.web.Widget.extend({ template: 'KanbanView.quick_create', - + /** * close_btn: If true, the widget will display a "Close" button able to trigger * a "close" event.