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

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

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

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.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-kanban-edit-column/+merge/114345
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-10 15:03:13 +0000
+++ addons/web_kanban/static/src/css/kanban.css	2012-07-11 07:27:21 +0000
@@ -49,7 +49,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;
 }
@@ -519,3 +518,12 @@
   padding: 0px;
   background: white;
 }
+
+.openerp .oe_kanban_create_group {
+  display: none;
+}
+.openerp .oe_kanban_add_group {
+  font-weight: bold;
+  font-size: 13px;
+  cursor: pointer;
+}

=== modified file 'addons/web_kanban/static/src/css/kanban.sass'
--- addons/web_kanban/static/src/css/kanban.sass	2012-07-10 15:03:13 +0000
+++ addons/web_kanban/static/src/css/kanban.sass	2012-07-11 07:27:21 +0000
@@ -63,7 +63,6 @@
     .oe_kanban_group_title
         font-size: 16px
         font-weight: bold
-        min-height: 30px
         color: #333333
         text-shadow: 0 1px 0 white
         > span
@@ -123,7 +122,6 @@
         width: 16px
         height: 16px
         background: url(/web_kanban/static/src/img/minus-icon.png) no-repeat
-    .oe_kanban_group_folded .oe_kanban_fold_icon
     // }}}
     // KanbanQuickCreate {{{
     .oe_kanban_add, .oe_kanban_header .oe_dropdown_toggle
@@ -433,6 +431,13 @@
     .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
 
 // 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-05 12:22:59 +0000
+++ addons/web_kanban/static/src/js/kanban.js	2012-07-11 07:27:21 +0000
@@ -41,12 +41,14 @@
         this.currently_dragging = {};
         this.limit = options.limit || 80;
         this.add_group_mutex = new $.Mutex();
+        this.group_field = {};
     },
     destroy: function() {
         this._super.apply(this, arguments);
         $('html').off('click.kanban');
     },
     on_loaded: function(data) {
+
         this.fields_view = data;
         this.$element.addClass(this.fields_view.arch.attrs['class']);
         this.$buttons = $(QWeb.render("KanbanView.buttons", {'widget': this}));
@@ -61,6 +63,7 @@
         this.fields_keys = _.keys(this.fields_view.fields);
         this.add_qweb_template();
         this.has_been_loaded.resolve();
+
         return $.when();
     },
     _is_quick_create_enabled: function() {
@@ -167,10 +170,35 @@
         this.search_group_by = group_by;
         $.when(this.has_been_loaded).then(function() {
             self.group_by = group_by.length ? group_by[0] : self.fields_view.arch.attrs.default_group_by;
+            self.dataset.call('fields_get', self.group_by ? [self.group_by] : [], function (fields) {
+                if(fields[self.group_by] && fields[self.group_by].type === "many2one"){
+                        self.group_field = fields[self.group_by];
+                        self.add_group();
+                }
+             });
             self.datagroup = new instance.web.DataGroup(self, self.dataset.model, domain, context, self.group_by ? [self.group_by] : []);
             self.datagroup.list(self.fields_keys, self.do_process_groups, self.do_process_dataset);
         });
     },
+    add_group:function(){
+      var self = this,
+            action = {
+            name: _t("Add column"),
+            res_model: self.group_field.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;
         this.add_group_mutex.exec(function() {
@@ -292,9 +320,13 @@
             unfolded += group.state.folded ? 0 : 1;
             group.$element.css('width', '');
         });
+        var folded_width = Math.round((100 / this.groups.length) / 4);
+        var unfolded_width = Math.round((100 - (folded_width * (this.groups.lenth - unfolded))) / unfolded)
         _.each(this.groups, function(group) {
             if (!group.state.folded) {
-                group.$element.css('width', Math.round(100/unfolded) + '%');
+                group.$element.css('width', unfolded_width -  + '%');
+            }else{
+                group.$element.css('width', folded_width + '%');
             }
         });
     },
@@ -380,7 +412,10 @@
         }
         this.state = this.view.state.groups[key];
         this.$records = null;
-
+        this.group_field = parent.group_field || null;
+        if(this.group_field){
+            this.group_dataset = new instance.web.DataSet(this, self.group_field.relation);
+        }
         this.records = [];
         this.$has_been_started.then(function() {
             self.do_add_records(records);
@@ -397,11 +432,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 = {};
@@ -423,6 +454,18 @@
         this.$records.data('widget', this);
         this.$has_been_started.resolve();
         this.compute_cards_auto_height();
+        
+        this.$element.find('.oe_dropdown_menu').click(function(event) {
+            if(event.target.dataset.type === "fold"){
+                var fold = $(event.target);
+                (fold.text() === "Fold")?fold.text(_t("Unfold")):fold.text(_t("Fold"));
+                self.do_toggle_fold();
+                self.view.compute_groups_width();
+            }else if(! _.isNull(self.group_field)){
+                var func = self["do_action_" + event.target.dataset.type];
+                if( typeof func === "function")func();
+            }
+        })
         return def;
     },
     compute_cards_auto_height: function() {
@@ -446,6 +489,34 @@
             this.$records.remove();
         }
     },
+    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();
+                    })
+                })
+        }
+    },
     do_show_more: function(evt) {
         var self = this;
         this.dataset.read_slice(this.view.fields_keys.concat(['__last_update']), {

=== modified file 'addons/web_kanban/static/src/xml/web_kanban.xml'
--- addons/web_kanban/static/src/xml/web_kanban.xml	2012-07-06 16:43:57 +0000
+++ addons/web_kanban/static/src/xml/web_kanban.xml	2012-07-11 07:27:21 +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