summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@openerp.com>2012-11-07 18:29:56 +0100
committerChristophe Simonis <chs@openerp.com>2012-11-07 18:29:56 +0100
commite3f0deff48ffd80adabc42cd0884312d3b06ebdd (patch)
tree33c0a590277f64c4ed6aeb2dbb340ef7700bad1c /addons/web/static/src/js
parentc8e1d477990430028f9ad68d295b8d3d4017fd46 (diff)
parenta963bd019a70c58adf6e5a190bcb3294493bdcb5 (diff)
merge upstream
bzr revid: chs@openerp.com-20121107172956-yq0di9lgw3x18ht2
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/search.js17
-rw-r--r--addons/web/static/src/js/view_form.js87
-rw-r--r--addons/web/static/src/js/view_list.js7
-rw-r--r--addons/web/static/src/js/view_tree.js105
4 files changed, 145 insertions, 71 deletions
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index b2ded00c105..d005c79e9b2 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -1656,11 +1656,20 @@ instance.web.search.Advanced = instance.web.search.Input.extend({
});
},
append_proposition: function () {
+ var self = this;
return (new instance.web.search.ExtendedSearchProposition(this, this.fields))
- .appendTo(this.$('ul'));
+ .appendTo(this.$('ul')).then(function () {
+ self.$('button.oe_apply').prop('disabled', false);
+ });
+ },
+ remove_proposition: function (prop) {
+ // removing last proposition, disable apply button
+ if (this.getChildren().length <= 1) {
+ this.$('button.oe_apply').prop('disabled', true);
+ }
+ prop.destroy();
},
commit_search: function () {
- var self = this;
// Get domain sections from all propositions
var children = this.getChildren();
var propositions = _.invoke(children, 'get_proposition');
@@ -1694,7 +1703,7 @@ instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @
'change .searchview_extended_prop_field': 'changed',
'click .searchview_extended_delete_prop': function (e) {
e.stopPropagation();
- this.destroy();
+ this.getParent().remove_proposition(this);
}
},
/**
@@ -1714,7 +1723,7 @@ instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @
this.value = null;
},
start: function () {
- this.changed();
+ return this._super().then(this.proxy('changed'));
},
changed: function() {
var nval = this.$(".searchview_extended_prop_field").val();
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 07c237ae0d8..e3b4b98a364 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -2216,6 +2216,13 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(instance.we
},
focus: function() {
this.$('input:first').focus();
+ },
+ set_dimensions: function (height, width) {
+ this._super(height, width);
+ this.$('input').css({
+ height: height,
+ width: width
+ });
}
});
@@ -2502,7 +2509,7 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(instance.we
this.$textarea.focus();
},
set_dimensions: function (height, width) {
- this._super();
+ this._super(height, width);
this.$textarea.css({
width: width,
minHeight: height
@@ -2664,6 +2671,13 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
},
focus: function() {
this.$el.find('select:first').focus();
+ },
+ set_dimensions: function (height, width) {
+ this._super(height, width);
+ this.$('select').css({
+ height: height,
+ width: width
+ });
}
});
@@ -3146,6 +3160,62 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
this.ed_def.reject();
return instance.web.form.CompletionFieldMixin._search_create_popup.apply(this, arguments);
},
+ set_dimensions: function (height, width) {
+ this._super(height, width);
+ this.$input.css('height', height);
+ }
+});
+
+instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({
+ template: 'Many2OneButton',
+ init: function(field_manager, node) {
+ this._super.apply(this, arguments);
+ },
+ start: function() {
+ this._super.apply(this, arguments);
+ this.set_button();
+ },
+ set_button: function() {
+ var self = this;
+ if (this.$button) {
+ this.$button.remove();
+ }
+ var options = {};
+ try {
+ options = py.eval(this.node.attrs.options);
+ } catch (e) {}
+ if (options.label) {
+ this.string = this.get('value') ? _t(options.label.edit) : _t(options.label.create);
+ } else {
+ this.string = '';
+ }
+ this.node.attrs.icon = this.get('value') ? '/web/static/src/img/icons/gtk-yes.png' : '/web/static/src/img/icons/gtk-no.png';
+ this.$button = $(QWeb.render('WidgetButton', {'widget': this}));
+ this.$el.append(this.$button);
+ this.$button.on('click', self.on_click);
+ },
+ on_click: function(ev) {
+ var self = this;
+ this.popup = new instance.web.form.FormOpenPopup(this);
+ this.popup.show_element(
+ this.field.relation,
+ this.get('value'),
+ this.build_context(),
+ {title: this.string}
+ );
+ this.popup.on('create_completed write_completed', self, function(r) {
+ self.set_value(r);
+ });
+ },
+ set_value: function(value_) {
+ var self = this;
+ if (value_ instanceof Array) {
+ value_ = value_[0];
+ }
+ value_ = value_ || false;
+ this.set('value', value_);
+ this.set_button();
+ },
});
/*
@@ -3922,6 +3992,8 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(in
var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context());
var values = self.get("value")
var handle_names = function(data) {
+ if (self.isDestroyed())
+ return;
var indexed = {};
_.each(data, function(el) {
indexed[el[0]] = el;
@@ -4420,6 +4492,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({
this.destroy();
},
destroy: function () {
+ this.trigger('closed');
this.$el.dialog('close');
this._super();
},
@@ -4823,6 +4896,7 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({
instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
template: 'FieldBinaryImage',
+ placeholder: "/web/static/src/img/placeholder.png",
render_value: function() {
var self = this;
var url;
@@ -4836,7 +4910,7 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + id + '&field=' + field + '&t=' + (new Date().getTime());
} else {
- url = "/web/static/src/img/placeholder.png";
+ url = this.placeholder;
}
var $img = $(QWeb.render("FieldBinaryImage-img", { widget: this, url: url }));
this.$el.find('> img').remove();
@@ -4849,10 +4923,10 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
$img.css("margin-left", "" + (self.options.size[0] - $img.width()) / 2 + "px");
$img.css("margin-top", "" + (self.options.size[1] - $img.height()) / 2 + "px");
});
- },
- on_file_change: function() {
- this.render_value();
- this._super.apply(this, arguments);
+ $img.on('error', function() {
+ $img.attr('src', self.placeholder);
+ instance.webclient.notification.warn(_t("Image"), _t("Could not display the selected image."));
+ });
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
this.internal_set_value(file_base64);
@@ -5132,6 +5206,7 @@ instance.web.form.widgets = new instance.web.Registry({
'datetime' : 'instance.web.form.FieldDatetime',
'selection' : 'instance.web.form.FieldSelection',
'many2one' : 'instance.web.form.FieldMany2One',
+ 'many2onebutton' : 'instance.web.form.Many2OneButton',
'many2many' : 'instance.web.form.FieldMany2Many',
'many2many_tags' : 'instance.web.form.FieldMany2ManyTags',
'many2many_kanban' : 'instance.web.form.FieldMany2ManyKanban',
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index ab50ae933d9..e59fb3c4d84 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -2012,6 +2012,7 @@ instance.web.list.columns = new instance.web.Registry({
'field.progressbar': 'instance.web.list.ProgressBar',
'field.handle': 'instance.web.list.Handle',
'button': 'instance.web.list.Button',
+ 'field.many2onebutton': 'instance.web.list.Many2OneButton',
});
instance.web.list.columns.for_ = function (id, field, node) {
var description = _.extend({tag: node.tag}, field, node.attrs);
@@ -2199,5 +2200,11 @@ instance.web.list.Handle = instance.web.list.Column.extend({
return '<div class="oe_list_handle">';
}
});
+instance.web.list.Many2OneButton = instance.web.list.Column.extend({
+ _format: function (row_data, options) {
+ this.has_value = !!row_data[this.id].value;
+ return QWeb.render('Many2OneButton.cell', {'widget': this});
+ },
+});
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js
index 05760420ba8..3f1dfabe80a 100644
--- a/addons/web/static/src/js/view_tree.js
+++ b/addons/web/static/src/js/view_tree.js
@@ -45,7 +45,7 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
view_type: "tree",
toolbar: this.view_manager ? !!this.view_manager.sidebar : false,
context: this.dataset.get_context()
- }).then(this.on_loaded);
+ }, this.on_loaded);
},
/**
* Returns the list of fields needed to correctly read objects.
@@ -63,12 +63,6 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
}
return fields;
},
- store_record:function(records){
- var self = this;
- _(records).each(function (record) {
- self.records[record.id] = record;
- });
- },
on_loaded: function (fields_view) {
var self = this;
var has_toolbar = !!fields_view.arch.attrs.toolbar;
@@ -93,19 +87,17 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
this.$el.addClass(this.fields_view.arch.attrs['class']);
this.dataset.read_slice(this.fields_list()).then(function(records) {
- self.store_record(records);
if (!has_toolbar) {
// WARNING: will do a second read on the same ids, but only on
// first load so not very important
- self.render_data({'null':records})
- self.getdata(_.pluck(records,"id"));
+ self.getdata(null, _(records).pluck('id'));
return;
}
var $select = self.$el.find('select')
.change(function () {
var $option = $(this).find(':selected');
- self.getdata($option.val());
+ self.getdata($option.val(), $option.data('children'));
});
_(records).each(function (record) {
self.records[record.id] = record;
@@ -120,12 +112,7 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
$select.change();
}
});
- this.$el.find("#tree_view_expand").click(function(){
- self.expand_all();
- });
- this.$el.find("#tree_view_collapse").click(function(){
- self.collpase_all();
- });
+
// TODO store open nodes in url ?...
this.do_push_state({});
@@ -141,22 +128,6 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
return [color, py.parse(py.tokenize(expr)), expr];
}).value();
},
- expand_all: function(){
- var self = this;
- var tr = this.$el.find(".oe-treeview-table tbody tr[id^='treerow_']");
- _.each(tr,function(rec){
- self.showcontent($(rec).attr('data-id'),true);
- });
- },
- collpase_all: function(){
- var self = this;
- var root_tr = this.$el.find(".oe-treeview-table tbody tr[data-level='"+1+"']");
- _.each(root_tr,function(rec){
- if($(rec).hasClass('oe_open')){
- self.showcontent($(rec).attr('data-id'),false);
- }
- });
- },
/**
* Returns the color for the provided record in the current view (from the
* ``@colors`` attribute)
@@ -193,44 +164,50 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
});
this.$el.delegate('.treeview-tr', 'click', function () {
- var $this = $(this),
+ var is_loaded = 0,
+ $this = $(this),
record_id = $this.data('id'),
- bool = $this.parent().hasClass('oe_open');
- self.showcontent(record_id, !bool);
+ record = self.records[record_id],
+ children_ids = record[self.children_field];
+
+ _(children_ids).each(function(childid) {
+ if (self.$el.find('#treerow_' + childid).length) {
+ if (self.$el.find('#treerow_' + childid).is(':hidden')) {
+ is_loaded = -1;
+ } else {
+ is_loaded++;
+ }
+ }
+ });
+ if (is_loaded === 0) {
+ if (!$this.parent().hasClass('oe_open')) {
+ self.getdata(record_id, children_ids);
+ }
+ } else {
+ self.showcontent(record_id, is_loaded < 0);
+ }
});
},
// get child data of selected value
- getdata: function (id) {
+ getdata: function (id, children_ids) {
var self = this;
- var parent_child ={};
- id = _.isArray(id)?id:parseInt(id);
- var ir_model_data = new instance.web.Model(this.model,self.dataset.get_context() || {},[['id','child_of',id]]).query();
- ir_model_data._execute().then(function(records){
- self.store_record(records);
- _.each(records,function(rec){
- if(rec[self.children_field].length === 0)return;
- parent_child[rec.id] = [];
- _.each(rec[self.children_field],function(key){
- parent_child[rec.id].push(self.records[key]);
- });
- })
- self.render_data(parent_child);
- });
- },
- render_data: function(groupby){
- var self = this;
- _.each(_.keys(groupby),function(key){
- var $curr_node = self.$el.find('#treerow_' + key);
- var record = groupby[key];
+
+ self.dataset.read_ids(children_ids, this.fields_list()).then(function(records) {
+ _(records).each(function (record) {
+ self.records[record.id] = record;
+ });
+
+ var $curr_node = self.$el.find('#treerow_' + id);
var children_rows = QWeb.render('TreeView.rows', {
- 'records': record,
+ 'records': records,
'children_field': self.children_field,
'fields_view': self.fields_view.arch.children,
'fields': self.fields,
- 'level': ($curr_node.data('level') || 0) + 1,
+ 'level': $curr_node.data('level') || 0,
'render': instance.web.format_value,
'color_for': self.color_for
});
+
if ($curr_node.length) {
$curr_node.addClass('oe_open');
$curr_node.after(children_rows);
@@ -238,10 +215,8 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
self.$el.find('tbody').html(children_rows);
}
});
- self.collpase_all();
},
-
// Get details in listview
activate: function(id) {
var self = this;
@@ -284,5 +259,13 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
}, this);
},
+ do_show: function () {
+ this.$el.show();
+ },
+
+ do_hide: function () {
+ this.$el.hide();
+ this.hidden = true;
+ }
});
};