Jiten (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-kanban-edit-column into lp:openerp-web.

Requested reviews:
  Jiten (OpenERP) (jiten-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-kanban-edit-column/+merge/116603

Improved Kanban view for m2o grouped field (Done by VME).
- Add link like 'Add a new column' to create a new column.
- Edit column
- Delete column
- Fold/Unfold the column.

- Implement Drag & Drop kanban column to set sequence of stage.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-kanban-edit-column/+merge/116603
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-kanban-edit-column.
=== modified file 'addons/web_kanban/static/src/css/kanban.css'
--- addons/web_kanban/static/src/css/kanban.css	2012-07-18 14:27:08 +0000
+++ addons/web_kanban/static/src/css/kanban.css	2012-07-25 08:54:20 +0000
@@ -1,3 +1,4 @@
+@charset "utf-8";
 .openerp .oe_kanban_view {
   background: url(/web/static/src/img/form_sheetbg.png);
   height: inherit;
@@ -49,7 +50,6 @@
 .openerp .oe_kanban_view .oe_kanban_group_title {
   font-size: 16px;
   font-weight: bold;
-  min-height: 30px;
   color: #333333;
   text-shadow: 0 1px 0 white;
 }
@@ -103,7 +103,7 @@
   white-space: nowrap;
   display: none;
   position: absolute;
-  top: 10px;
+  top: 120px;
 }
 .openerp .oe_kanban_view .oe_kanban_fold_icon {
   cursor: pointer;
@@ -525,3 +525,16 @@
   padding: 0px;
   background: white;
 }
+
+.openerp .oe_kanban_create_group {
+  display: none;
+}
+.openerp .oe_kanban_add_group {
+  font-weight: bold;
+  font-size: 13px;
+  cursor: pointer;
+}
+
+.openerp .oe_kanban_group_header {
+  cursor: move;
+}

=== modified file 'addons/web_kanban/static/src/css/kanban.sass'
--- addons/web_kanban/static/src/css/kanban.sass	2012-07-18 14:27:08 +0000
+++ addons/web_kanban/static/src/css/kanban.sass	2012-07-25 08:54:20 +0000
@@ -64,7 +64,6 @@
     .oe_kanban_group_title
         font-size: 16px
         font-weight: bold
-        min-height: 30px
         color: #333333
         text-shadow: 0 1px 0 white
         > span
@@ -113,7 +112,7 @@
         white-space: nowrap
         display: none
         position: absolute
-        top: 10px
+        top: 120px
     .oe_kanban_fold_icon
         cursor: pointer
         float: left
@@ -438,6 +437,15 @@
     .oe_kanban_column, .oe_kanban_group_header
         padding: 0px
         background: #ffffff
+.openerp
+    .oe_kanban_create_group
+        display: none
+    .oe_kanban_add_group
+        font-weight: bold
+        font-size: 13px
+        cursor: pointer
+.openerp .oe_kanban_group_header
+    cursor: move
 
 // au BufWritePost,FileWritePost *.sass :!sass --style expanded --line-numbers <afile> > "%:p:r.css"
 // vim:tabstop=4:shiftwidth=4:softtabstop=4:fdm=marker:

=== modified file 'addons/web_kanban/static/src/js/kanban.js'
--- addons/web_kanban/static/src/js/kanban.js	2012-07-12 15:26:35 +0000
+++ addons/web_kanban/static/src/js/kanban.js	2012-07-25 08:54:20 +0000
@@ -171,26 +171,74 @@
             self.datagroup.list(self.fields_keys, self.do_process_groups, self.do_process_dataset);
         });
     },
+    add_group:function(obj){
+      var self = this,
+            action = {
+            name: _t("Add column"),
+            res_model: obj.relation,
+            views: [[false, 'form']],
+            type: 'ir.actions.act_window',
+            target: "new",
+            flags: {
+                action_buttons: true,
+            }
+        },action_manager = new instance.web.ActionManager(self);
+        
+        this.$buttons.find('.oe_kanban_create_group *').unbind();
+        this.$buttons.find(".oe_kanban_create_group")
+            .css('display','inline')
+            .find('.oe_kanban_add_group')
+            .click(function(){action_manager.do_action(action,self.do_reload);});
+    },
     do_process_groups: function(groups) {
+        var self = this,other = {},defer = $.Deferred();
+        self.get_group_data(other,_.pluck(groups,"value"),defer)
+        return $.when(defer).done(function(){
+            self.add_group_mutex.exec(function() {
+                self.do_clear_groups();
+                self.dataset.ids = [];
+                var remaining = groups.length - 1,
+                    groups_array = [];
+                return $.when.apply(null,_.map(groups, function (group, index) {
+                    var dataset = new instance.web.DataSetSearch(self, self.dataset.model, group.context, group.domain);
+                    return dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit })
+                        .pipe(function(records) {
+                            self.dataset.ids.push.apply(self.dataset.ids, dataset.ids);
+                            var obj = (_.isEmpty(other))?(instance.web_kanban.KanbanGroup):(instance.web_kanban.KanbanGroupFUD);
+                            groups_array[index] = new (obj)(self, records, group, dataset, other);
+                            if (!remaining--) {
+                                self.dataset.index = self.dataset.size() ? 0 : null;
+                                return self.do_add_groups(groups_array);
+                            }
+                    });
+                }));
+            });
+        });
+    },
+    get_group_data:function(other,groups_value,defer){
         var self = this;
-        this.add_group_mutex.exec(function() {
-            self.do_clear_groups();
-            self.dataset.ids = [];
-            var remaining = groups.length - 1,
-                groups_array = [];
-            return $.when.apply(null, _.map(groups, function (group, index) {
-                var dataset = new instance.web.DataSetSearch(self, self.dataset.model, group.context, group.domain);
-                return dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit })
-                    .pipe(function(records) {
-                        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);
-                        }
-                });
-            }));
+        if(!self.group_by)return defer.resolve();
+        this.dataset.call('fields_get', _.isArray(self.group_by)  ? self.group_by : [self.group_by],function (fields) {
+            if(fields[self.group_by] && fields[self.group_by].type === "many2one"){
+                
+                other["group_field"] = fields[self.group_by];
+                other["group_dataset"] = new instance.web.DataSet(self, fields[self.group_by].relation);
+                other["group_record"] = {};
+                var ids = _.chain(groups_value)
+                            .flatten()
+                            .reject(function(a){return typeof a === "string"}).value();
+                            
+                other["group_dataset"].read_ids(ids,[]).then(function(results) {
+                        _.each(results,function(res){other["group_record"][res.id] = res;});
+                        defer.resolve();
+                    });
+                    
+                self.add_group(fields[self.group_by]);
+            }else{
+                defer.resolve();
+            }
         });
+        return defer;
     },
     do_process_dataset: function(dataset) {
         var self = this;
@@ -231,8 +279,51 @@
         });
         return $.when.apply(null, groups_started).then(function () {
             self.on_groups_started();
+            self.on_column_header();
         });
     },
+    on_column_header: function(){
+      var old_index,new_index,self = this,widget,start_seq,stop_seq,old_id;
+      this.$element.find('.oe_kanban_groups_headers').sortable({
+                connectWith: '.oe_kanban_groups_headers',
+                start:function(event, ui){
+                    old_index = ui.item.index();
+                    var temp  = self.$element.find(".oe_kanban_column:eq("+old_index+")").data('widget');
+                    start_seq = temp.group_record.sequence;
+                    old_id = temp.group_record.id;
+                },
+                stop:function(event, ui){
+                    new_index = ui.item.index();
+                    if(old_index !== new_index){
+                        stop_seq = (self.$element.find(".oe_kanban_column:eq("+new_index+")").data('widget')).group_record.sequence;
+                        $.when.apply(null,self.change_sequence(start_seq,stop_seq,old_id)).then(function() {
+                            var $old_element = self.$element.find(".oe_kanban_groups_records td:eq("+old_index+")").detach();
+                            self.$element.find(".oe_kanban_groups_records td:eq("+(new_index)+")").before($old_element);
+                        });
+                    }
+                }
+            });
+    },
+    change_sequence: function(start,stop,old_id){
+        var defer = [],reverse =false;
+        if(start > stop){
+            stop=(start+stop)-(start=stop);
+            reverse = true;
+        }
+        _(this.groups).each(function(group){
+            if(old_id == group.group_record.id){
+                var value = (reverse)?start:stop;
+                group.group_record.sequence = value;
+                defer.push(group.group_dataset.write(group.group_record.id,{"sequence":group.group_record.sequence}));
+            }
+            else if(start <= group.group_record.sequence && group.group_record.sequence <= stop){
+                var value = (reverse)?1:-1;
+                group.group_record.sequence = group.group_record.sequence + value;
+                defer.push(group.group_dataset.write(group.group_record.id,{"sequence":group.group_record.sequence}));
+            }
+        })
+        return defer;
+    },
     on_groups_started: function() {
         var self = this;
         this.compute_groups_width();
@@ -264,6 +355,7 @@
         var self = this;
         $.fn.tipsy.clear();
         $(old_group.$element).add(new_group.$element).find('.oe_kanban_aggregates, .oe_kanban_group_length').hide();
+        
         if (old_group === new_group) {
             new_group.records.splice(old_index, 1);
             new_group.records.splice(new_index, 0, record);
@@ -385,7 +477,7 @@
         }
         this.state = this.view.state.groups[key];
         this.$records = null;
-
+        
         this.records = [];
         this.$has_been_started.then(function() {
             self.do_add_records(records);
@@ -402,11 +494,7 @@
         }
         this.$records = $(QWeb.render('KanbanView.group_records_container', { widget : this}));
         this.$records.appendTo(this.view.$element.find('.oe_kanban_groups_records'));
-        this.$element.find(".oe_kanban_fold_icon").click(function() {
-            self.do_toggle_fold();
-            self.view.compute_groups_width();
-            return false;
-        });
+
         this.$element.find('.oe_kanban_add').click(function () {
             if (self.quick) { return; }
             var ctx = {};
@@ -424,10 +512,12 @@
         if (this.state.folded) {
             this.do_toggle_fold();
         }
+
         this.$element.data('widget', this);
         this.$records.data('widget', this);
         this.$has_been_started.resolve();
         this.compute_cards_auto_height();
+        
         return def;
     },
     compute_cards_auto_height: function() {
@@ -484,6 +574,7 @@
     do_toggle_fold: function(compute_width) {
         this.$element.add(this.$records).toggleClass('oe_kanban_group_folded');
         this.state.folded = this.$element.is('.oe_kanban_group_folded');
+        this.$element.find("ul.oe_dropdown_menu li a:first").text((this.state.folded)?_t("Unfold"):_t("Fold"));
     },
     do_save_sequences: function() {
         var self = this;
@@ -507,7 +598,67 @@
             });
     }
 });
+instance.web_kanban.KanbanGroupFUD = instance.web_kanban.KanbanGroup.extend({
+    init:function(self, records, group, dataset, other){
+        this._super(self, records, group, dataset);
+        this.group_dataset = other["group_dataset"];
+        this.group_field = other["group_field"];
+        this.group_record = other["group_record"][group.value[0]];
+    },
+    start: function(){
+        var self =this,
+            return_obj = this._super.apply(this,arguments)
+            parent = this.getParent();
+        self.$element.find('.oe_dropdown_menu').click(function(event) {
+            if(event.target.dataset.type === "fold"){
+                var fold = $(event.target);
+                self.group_dataset.write(self.group.value[0],{'column_fold': !self.group_record.column_fold})
+                .done(function(res){
+                    if(!res.result)return;
+                    self.fold_unfold();
+                });
+                }else{
+                var func = self["do_action_" + event.target.dataset.type];
+                if( typeof func === "function")func();
+            }
+        });
+        if(!this.state.folded && self.group_record.column_fold)self.fold_unfold();
+        return return_obj;
+    },
+    fold_unfold: function(){
+        this.do_toggle_fold();
+        this.view.compute_groups_width();
+    },
+    do_action_edit : function() {
+        var parent = this.getParent(),
+        action = {
+            res_id:this.group.value[0],
+            name : _t("Edit column"),
+            res_model : this.group_field.relation,
+            views : [[false, 'form']],
+            type : 'ir.actions.act_window',
+            target : "new",
+            flags : {
+                action_buttons : true,
+            }
+        },action_manager = new instance.web.ActionManager(this);
+        action_manager.do_action(action,parent.do_reload);
+    },
+    do_action_delete : function() {
+        if (confirm(_t("Are you sure you want to delete this group and related records ?"))) {
+            var self = this,
+                parent = self.getParent(),
+                ids =  _.pluck(this.records, "id");
+                self.group_dataset.unlink([self.group.value[0]]).then(function(){
+                    self.view.dataset.unlink(ids).then(function(){
+                       self.group.destroy();
+                       parent.do_reload();
+                    })
+                })
+        }
+    },
 
+})
 instance.web_kanban.KanbanRecord = instance.web.OldWidget.extend({
     template: 'KanbanView.record',
     init: function (parent, record) {

=== modified file 'addons/web_kanban/static/src/xml/web_kanban.xml'
--- addons/web_kanban/static/src/xml/web_kanban.xml	2012-07-11 16:32:23 +0000
+++ addons/web_kanban/static/src/xml/web_kanban.xml	2012-07-25 08:54:20 +0000
@@ -16,6 +16,11 @@
             <button type="button" class="oe_button oe_kanban_button_new oe_highlight oe_form_button_hi">
                 <t t-esc="widget.options.create_text || _t('Create')"/>
             </button>
+            <span class = "oe_kanban_create_group">
+                <span>or</span>
+                <a class = "oe_kanban_add_group">Add a new column</a>
+            </span>
+           
         </t>
     </t>
 </div>
@@ -30,14 +35,15 @@
                     <div t-attf-class="oe_kanban_group_title #{widget.undefined_title ? 'oe_kanban_group_title_undefined' : ''}">
                         <span><t t-esc="widget.title"/></span>
                         <span class="oe_kanban_group_length">(<t t-esc="widget.group.length"/>)</span>
-                        <div class="oe_dropdown_toggle oe_dropdown_kanban">
+
+                    </div>
+                    <div class="oe_dropdown_toggle oe_dropdown_kanban">
                           <span class="oe_e">í</span>
                           <ul class="oe_dropdown_menu">
                             <li><a data-type="fold" href="#" class="">Fold</a></li>
                             <li><a data-type="edit" href="#" class="">Edit</a></li>
                             <li><a data-type="delete" href="#" class="">Delete</a></li>
                           </ul>
-                        </div>
                     </div>
                     <div class="oe_clear"/>
                     <ul class="oe_kanban_aggregates">

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to