Xavier (Open ERP) has proposed merging
lp:~openerp-dev/openerp-web/trunk-kanban-quick-create-xmo into lp:openerp-web.
Requested reviews:
Fabien (Open ERP) (fp-tinyerp)
Fabien Meghazi (OpenERP) (fme)
Aline (OpenERP) (apr-tinyerp)
OpenERP R&D Web Team (openerp-dev-web)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-kanban-quick-create-xmo/+merge/102116
Quick-creation widget thingie at the top of every Kanban view: click on [+],
get field, typetypetype, click [Add] (or press [Return]), record gets added at
the top of the column with just the _rec_name and the grouping field set.
--
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-kanban-quick-create-xmo/+merge/102116
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openerp-web/trunk-kanban-quick-create-xmo.
=== modified file 'addons/web_kanban/static/src/css/kanban.css'
--- addons/web_kanban/static/src/css/kanban.css 2012-04-10 14:20:51 +0000
+++ addons/web_kanban/static/src/css/kanban.css 2012-04-16 14:35:36 +0000
@@ -224,6 +224,30 @@
line-height: 1em;
}
+.openerp .oe_kanban_add {
+ cursor: pointer;
+ position: absolute;
+ top: 6px;
+ right: 6px;
+ width: 16px;
+ height: 16px;
+ background: url(/web_kanban/static/src/img/plus-icon.png) no-repeat;
+}
+
+.openerp .oe_kanban_quick_create {
+ /* apply block formatting context */
+ overflow: hidden;
+}
+.openerp .oe_kanban_quick_create input {
+ display: block;
+ /* margins within width */
+ box-sizing: border-box;
+ width: 100%;
+}
+.openerp .oe_kanban_quick_create button {
+ float: right;
+}
+
/* Custom colors are also present in kanban.js */
/* Custom color#0 */
.openerp .oe_kanban_color_0 .oe_kanban_color_bglight {
=== modified file 'addons/web_kanban/static/src/js/kanban.js'
--- addons/web_kanban/static/src/js/kanban.js 2012-04-10 14:20:51 +0000
+++ addons/web_kanban/static/src/js/kanban.js 2012-04-16 14:35:36 +0000
@@ -351,6 +351,12 @@
self.view.compute_groups_width();
return false;
});
+ this.$element.find('.oe_kanban_add').click(function () {
+ if (self.quick) { return; }
+ self.quick = new openerp.web_kanban.QuickCreate(this)
+ .on('added', self, self.proxy('quick_add'));
+ self.quick.appendTo(self.$element.find('.oe_kanban_group_header'));
+ });
this.$records.find('.oe_kanban_show_more').click(this.do_show_more);
if (this.state.folded) {
this.do_toggle_fold();
@@ -373,12 +379,17 @@
'offset': self.dataset_offset += self.view.limit
}).then(this.do_add_records);
},
- do_add_records: function(records) {
+ do_add_records: function(records, prepend) {
var self = this;
_.each(records, function(record) {
var rec = new openerp.web_kanban.KanbanRecord(self, record);
- rec.insertBefore(self.$records.find('.oe_kanban_show_more'));
- self.records.push(rec);
+ if (!prepend) {
+ rec.insertBefore(self.$records.find('.oe_kanban_show_more'));
+ self.records.push(rec);
+ } else {
+ rec.prependTo(self.$records);
+ self.records.unshift(rec);
+ }
});
this.$records.find('.oe_kanban_show_more').toggle(this.records.length < this.dataset.size())
.find('.oe_kanban_remaining').text(this.dataset.size() - this.records.length);
@@ -401,6 +412,36 @@
self.view.dataset.write(record.id, { sequence : index });
});
}
+ },
+ /**
+ * Handles user event from nested quick creation view
+ *
+ * @param {String} name name to give to the new record
+ */
+ quick_add: function (name) {
+ var context = {};
+ context['default_' + this.view.group_by] = this.value;
+ // FIXME: what if name_create fails?
+ new openerp.web.Model(this.dataset.model).call(
+ 'name_create', [name], {context: new openerp.web.CompoundContext(
+ this.dataset.get_context(), context)})
+ .then(this.proxy('quick_created'))
+ },
+ /**
+ * Handles a non-erroneous response from name_create
+ *
+ * @param {(Id, String)} record name_get format for the newly created record
+ */
+ quick_created: function (record) {
+ var id = record[0], self = this;
+ this.quick.destroy();
+ delete this.quick;
+ new openerp.web.Model(this.dataset.model).call(
+ 'read', [[id], this.view.fields_keys], {})
+ .then(function (records) {
+ self.view.dataset.ids.push(id);
+ self.do_add_records(records, 'prepend');
+ });
}
});
@@ -602,6 +643,28 @@
}
}
});
+
+/**
+ * Quick creation view.
+ *
+ * Triggers a single event "added" with a single parameter "name", which is the
+ * name entered by the user
+ *
+ * @class
+ * @type {*}
+ */
+openerp.web_kanban.QuickCreate = openerp.web.Widget.extend({
+ template: 'KanbanView.quick_create',
+
+ start: function () {
+ var self = this;
+ this.$element.on('submit', function () {
+ self.trigger('added', self.$element.find('input').val());
+ return false;
+ });
+ return this._super();
+ }
+});
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
=== modified file 'addons/web_kanban/static/src/xml/web_kanban.xml'
--- addons/web_kanban/static/src/xml/web_kanban.xml 2012-04-10 14:20:51 +0000
+++ addons/web_kanban/static/src/xml/web_kanban.xml 2012-04-16 14:35:36 +0000
@@ -20,6 +20,7 @@
<t t-if="widget.view.group_by">
<div class="oe_kanban_group_header">
<div class="oe_kanban_fold_icon"></div>
+ <div class="oe_kanban_add"></div>
<div class="oe_fold_column">
<div t-attf-class="oe_kanban_group_title #{widget.undefined_title ? 'oe_kanban_group_title_undefined' : ''}">
<t t-esc="widget.title"/>
@@ -62,4 +63,8 @@
</tr>
</table>
</t>
+<form t-name="KanbanView.quick_create" class="oe_kanban_quick_create">
+ <input/>
+ <button type="submit">Add</button>
+</form>
</template>
_______________________________________________
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