Jiten (OpenERP)
2012-10-19 11:18:45 +05:30
37 changed files with 636 additions and 709 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
Don't stop the world now: asynchronous development and Javascript
=================================================================
Asynchronous Operations
=======================
As a language (and runtime), javascript is fundamentally
single-threaded. This means any blocking request or computation will
+7 -2
View File
@@ -95,8 +95,8 @@ DataGroup -> also Model
-----------------------
Alongside the deprecation of ``DataSet`` for
:js:class:`~openerp.web.Model`, OpenERP Web 7.0 also deprecates
``DataGroup`` and its subtypes in favor of a single method on
:js:class:`~openerp.web.Model`, OpenERP Web 7.0 removes
``DataGroup`` and its subtypes as public objects in favor of a single method on
:js:class:`~openerp.web.Query`:
:js:func:`~openerp.web.Query.group_by`.
@@ -116,3 +116,8 @@ Because it is heavily related to ``DataSet`` (as it *yields*
``DataGroup`` (if we want to stay consistent), which is a good time to
make the API more imperative and look more like what most developers
are used to.
But as ``DataGroup`` users in 6.1 were rare (and there really was little reason
to use it), it has been removed as a public API.
+2 -2
View File
@@ -1,5 +1,5 @@
Outside the box: network interactions
=====================================
RPC Calls
=========
Building static displays is all nice and good and allows for neat
effects (and sometimes you're given data to display from third parties
+20 -9
View File
@@ -25,7 +25,6 @@
display: none !important;
}
}
.openerp.openerp_webclient_container {
height: 100%;
position: relative;
@@ -2562,6 +2561,12 @@
.openerp .oe_list.oe_list_editable td.oe_list_record_delete {
position: absolute;
}
.openerp .oe_list.oe_list_editable.oe_editing .oe_edition .oe_list_field_cell:not(.oe_readonly) {
color: transparent;
}
.openerp .oe_list.oe_list_editable.oe_editing .oe_edition .oe_list_field_cell:not(.oe_readonly) * {
visibility: hidden;
}
.openerp .oe_list.oe_list_editable.oe_editing .oe_m2o_drop_down_button {
top: 5px;
}
@@ -2580,10 +2585,10 @@
}
.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_float input, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_view_integer input {
text-align: right;
width: 100%;
width: 100% !important;
}
.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_datetime > span, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_date > span {
width: 100%;
width: 100% !important;
}
.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_datetime input.oe_datepicker_master, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_date input.oe_datepicker_master {
width: 100% !important;
@@ -2592,6 +2597,9 @@
min-width: 0 !important;
max-width: none !important;
}
.openerp .oe_list_group_name {
white-space: nowrap;
}
.openerp .oe_form .oe_form_field_many2many > .oe_list .oe_list_pager_single_page {
display: none;
}
@@ -2651,14 +2659,17 @@
background: #eeeeee;
vertical-align: top;
}
.openerp .oe_list_content > thead th {
position: relative;
}
.openerp .oe_list_content td, .openerp .oe_list_content th {
padding: 3px 6px;
line-height: 18px;
}
.openerp .oe_list_content th:after {
.openerp .oe_list_content th.oe_sortable, .openerp .oe_list_content th.oe_sortable div {
cursor: pointer;
}
.openerp .oe_list_content th.oe_sortable div {
position: relative;
}
.openerp .oe_list_content th.oe_sortable div:after {
position: absolute;
right: 6px;
content: "";
@@ -2668,12 +2679,12 @@
border-color: black transparent;
visibility: hidden;
}
.openerp .oe_list_content th.sortup:after {
.openerp .oe_list_content th.sortup div:after {
visibility: visible;
filter: alpha(opacity=60);
opacity: 0.6;
}
.openerp .oe_list_content th.sortdown:after {
.openerp .oe_list_content th.sortdown div:after {
border-bottom: none;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
+15 -7
View File
@@ -2026,6 +2026,10 @@ $sheet-max-width: 860px
td.oe_list_record_delete
position: absolute
.oe_list.oe_list_editable.oe_editing
.oe_edition .oe_list_field_cell:not(.oe_readonly)
*
visibility: hidden
color: transparent
.oe_m2o_drop_down_button
top: 5px
.oe_m2o_cm_button
@@ -2040,15 +2044,17 @@ $sheet-max-width: 860px
&.oe_form_field_float,&.oe_form_view_integer
input
text-align: right
width: 100%
width: 100% !important
&.oe_form_field_datetime,&.oe_form_field_date
> span
width: 100%
width: 100% !important
input.oe_datepicker_master
width: 100% !important
.oe_form_field_float,.oe_form_view_integer,&.oe_form_field_datetime,&.oe_form_field_date
min-width: 0 !important
max-width: none !important
.oe_list_group_name
white-space: nowrap
// }}}
// FormView.many2many {{{
.oe_form .oe_form_field_many2many > .oe_list
@@ -2098,12 +2104,14 @@ $sheet-max-width: 860px
border-bottom: 2px solid #cacaca
background: #eee
vertical-align: top
th
position: relative
td, th
padding: 3px 6px
line-height: 18px
th:after
th.oe_sortable, th.oe_sortable div
cursor: pointer
th.oe_sortable div
position: relative
th.oe_sortable div:after
position: absolute
right: 6px
content: ""
@@ -2112,10 +2120,10 @@ $sheet-max-width: 860px
border-style: solid
border-color: #000 transparent
visibility: hidden
th.sortup:after
th.sortup div:after
visibility: visible
@include opacity(0.6)
th.sortdown:after
th.sortdown div:after
border-bottom: none
border-left: 4px solid transparent
border-right: 4px solid transparent
+23 -13
View File
@@ -70,7 +70,9 @@ instance.web.Dialog = instance.web.Widget.extend({
autoOpen: false,
position: [false, 40],
buttons: {},
beforeClose: function () { self.close(); },
beforeClose: function () {
self.trigger("closing");
},
resizeStop: this.on_resized
};
for (var f in this) {
@@ -84,6 +86,7 @@ instance.web.Dialog = instance.web.Widget.extend({
}
_.extend(this.dialog_options, options);
}
this.on("closing", this, this._closing);
},
get_options: function(options) {
var self = this,
@@ -126,13 +129,10 @@ instance.web.Dialog = instance.web.Widget.extend({
if (! this.dialog_inited)
this.init_dialog();
var o = this.get_options(options);
if (! this.params_buttons) {
this.$buttons.appendTo($("body"));
}
this.$buttons.appendTo($("body"));
instance.web.dialog(this.$el, o).dialog('open');
if (! this.params_buttons) {
this.$buttons.appendTo(this.$el.dialog("widget"));
}
this.$el.dialog("widget").find(".ui-dialog-buttonpane").remove();
this.$buttons.appendTo(this.$el.dialog("widget"));
if (o.height === 'auto' && o.max_height) {
this.$el.css({ 'max-height': o.max_height, 'overflow-y': 'auto' });
}
@@ -145,19 +145,23 @@ instance.web.Dialog = instance.web.Widget.extend({
if (! this.params_buttons) {
this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" />');
this.$el.dialog("widget").append(this.$buttons);
} else {
this.$buttons = this.$el.dialog("widget").find(".ui-dialog-buttonpane");
}
this.dialog_inited = true;
var res = this.start();
return res;
},
close: function() {
close: function() {
this.$el.dialog('close');
},
_closing: function() {
if (this.__tmp_dialog_destroying)
return;
if (this.dialog_options.destroy_on_close) {
this.__tmp_dialog_closing = true;
this.destroy();
this.__tmp_dialog_closing = undefined;
this.trigger("dialog_close");
}
},
on_resized: function() {
@@ -697,9 +701,12 @@ instance.web.Menu = instance.web.Widget.extend({
return this.do_reload();
},
do_reload: function() {
return this.rpc("/web/menu/load", {}).then(this.on_loaded);
var self = this;
return this.rpc("/web/menu/load", {}).then(function(r) {
self.menu_loaded(r);
});
},
on_loaded: function(data) {
menu_loaded: function(data) {
var self = this;
this.data = data;
this.renderElement();
@@ -716,6 +723,7 @@ instance.web.Menu = instance.web.Widget.extend({
if (self.current_menu) {
self.open_menu(self.current_menu);
}
this.trigger('menu_loaded', data);
this.has_been_loaded.resolve();
},
limit_entries: function() {
@@ -1116,9 +1124,11 @@ instance.web.WebClient = instance.web.Client.extend({
.pipe(function (result) {
var action = result;
if (options.needaction) {
action.context.search_default_needaction_pending = true;
action.context.search_default_message_unread = true;
}
return $.when(self.action_manager.do_action(action, null, true)).fail(function() {
return $.when(self.action_manager.do_action(action, {
clear_breadcrumbs: true,
})).fail(function() {
self.menu.open_menu(options.previous_menu_id);
});
});
+31 -66
View File
@@ -291,6 +291,17 @@ var Events = instance.web.Class.extend({
return this;
},
callbackList: function() {
var lst = [];
_.each(this._callbacks || {}, function(el, eventName) {
var node = el;
while ((node = node.next) && node.next) {
lst.push([eventName, node.callback, node.context]);
}
});
return lst;
},
trigger : function(events) {
var event, node, calls, tail, args, all, rest;
if (!(calls = this._callbacks))
@@ -369,9 +380,9 @@ instance.web.EventDispatcherMixin = _.extend({}, instance.web.ParentedMixin, {
event.source.__edispatcherEvents.off(event.name, event.func, self);
});
this.__edispatcherRegisteredEvents = [];
if(!this.__edispatcherEvents) {
debugger;
}
_.each(this.__edispatcherEvents.callbackList(), function(cal) {
this.off(cal[0], cal[2], cal[1]);
}, this);
this.__edispatcherEvents.off();
instance.web.ParentedMixin.destroy.call(this);
}
@@ -382,8 +393,17 @@ instance.web.PropertiesMixin = _.extend({}, instance.web.EventDispatcherMixin, {
instance.web.EventDispatcherMixin.init.call(this);
this.__getterSetterInternalMap = {};
},
set: function(map, options) {
options = options || {};
set: function(arg1, arg2, arg3) {
var map;
var options;
if (typeof arg1 === "string") {
map = {};
map[arg1] = arg2;
options = arg3 || {};
} else {
map = arg1;
options = arg2 || {};
}
var self = this;
var changed = false;
_.each(map, function(val, key) {
@@ -410,71 +430,16 @@ instance.web.CallbackEnabledMixin = _.extend({}, instance.web.PropertiesMixin, {
init: function() {
instance.web.PropertiesMixin.init.call(this);
var self = this;
var callback_maker = function(obj, name, method) {
var callback = function() {
var args = Array.prototype.slice.call(arguments);
self.trigger.apply(self, [name].concat(args));
var r;
for(var i = 0; i < callback.callback_chain.length; i++) {
var c = callback.callback_chain[i];
if(c.unique) {
callback.callback_chain.splice(i, 1);
i -= 1;
}
var result = c.callback.apply(c.self, c.args.concat(args));
if (c.callback === method) {
// return the result of the original method
r = result;
}
// TODO special value to stop the chain
// instance.web.callback_stop
}
return r;
};
callback.callback_chain = [];
callback.add = function(f) {
if(typeof(f) == 'function') {
f = { callback: f, args: Array.prototype.slice.call(arguments, 1) };
}
f.self = f.self || null;
f.args = f.args || [];
f.unique = !!f.unique;
if(f.position == 'last') {
callback.callback_chain.push(f);
} else {
callback.callback_chain.unshift(f);
}
return callback;
};
callback.add_first = function(f) {
return callback.add.apply(null,arguments);
};
callback.add_last = function(f) {
return callback.add({
callback: f,
args: Array.prototype.slice.call(arguments, 1),
position: "last"
});
};
callback.remove = function(f) {
callback.callback_chain = _.difference(callback.callback_chain, _.filter(callback.callback_chain, function(el) {
return el.callback === f;
}));
return callback;
};
return callback.add({
callback: method,
self:obj,
args:Array.prototype.slice.call(arguments, 3)
});
};
// Transform on_/do_* methods into callbacks
var callback_maker = function(fn) {
return function() {
return fn.apply(self, arguments);
}
};
for (var name in this) {
if(typeof(this[name]) == "function") {
this[name].debug_name = name;
if((/^on_|^do_/).test(name)) {
this[name] = callback_maker(this, name, this[name]);
this[name] = callback_maker(this[name]);
}
}
}
+8 -85
View File
@@ -120,6 +120,10 @@ instance.web.Query = instance.web.Class.extend({
if (_.isEmpty(grouping)) { return null; }
var self = this;
// FIXME: when pyeval is merged
var ctx = instance.session.test_eval_contexts(
[this._model.context(this._context)]);
return this._model.call('read_group', {
groupby: grouping,
fields: _.uniq(grouping.concat(this._fields || [])),
@@ -130,6 +134,8 @@ instance.web.Query = instance.web.Class.extend({
orderby: instance.web.serialize_sort(this._order_by) || false
}).pipe(function (results) {
return _(results).map(function (result) {
// FIX: querygroup initialization
_.defaults(result.__context, ctx);
return new instance.web.QueryGroup(
self._model.name, grouping[0], result);
});
@@ -350,89 +356,6 @@ instance.web.Model = instance.web.Class.extend({
},
});
instance.web.DataGroup = instance.web.CallbackEnabled.extend({
/**
* Management interface between views and grouped collections of OpenERP
* records.
*
* The root DataGroup is instantiated with the relevant information
* (a session, a model, a domain, a context and a group_by sequence), the
* domain and context may be empty. It is then interacted with via
* :js:func:`~instance.web.DataGroup.list`, which is used to read the
* content of the current grouping level.
*
* @constructs instance.web.DataGroup
* @extends instance.web.CallbackEnabled
*
* @param {instance.web.CallbackEnabled} parent widget
* @param {String} model name of the model managed by this DataGroup
* @param {Array} domain search domain for this DataGroup
* @param {Object} context context of the DataGroup's searches
* @param {Array} group_by sequence of fields by which to group
* @param {Number} [level=0] nesting level of the group
*/
init: function(parent, model, domain, context, group_by, level) {
this._super(parent, null);
this.model = new instance.web.Model(model, context, domain);
this.group_by = group_by;
this.context = context;
this.domain = domain;
this.level = level || 0;
},
list: function (fields, ifGroups, ifRecords) {
var self = this;
var query = this.model.query(fields).order_by(this.sort).group_by(this.group_by);
$.when(query).then(function (querygroups) {
// leaf node
if (!querygroups) {
var ds = new instance.web.DataSetSearch(self, self.model.name, self.model.context(), self.model.domain());
ds._sort = self.sort;
ifRecords(ds);
return;
}
// internal node
var child_datagroups = _(querygroups).map(function (group) {
var child_context = _.extend(
{}, self.model.context(), group.model.context());
var child_dg = new instance.web.DataGroup(
self, self.model.name, group.model.domain(),
child_context, group.model._context.group_by,
self.level + 1);
child_dg.sort = self.sort;
// copy querygroup properties
child_dg.__context = child_context;
child_dg.__domain = group.model.domain();
child_dg.folded = group.get('folded');
child_dg.grouped_on = group.get('grouped_on');
child_dg.length = group.get('length');
child_dg.value = group.get('value');
child_dg.openable = group.get('has_children');
child_dg.aggregates = group.get('aggregates');
return child_dg;
});
ifGroups(child_datagroups);
});
}
});
instance.web.StaticDataGroup = instance.web.DataGroup.extend({
/**
* A specialization of data groups, relying on a single static
* dataset as its records provider.
*
* @constructs instance.web.StaticDataGroup
* @extends instance.web.DataGroup
* @param {openep.web.DataSetStatic} dataset a static dataset backing the groups
*/
init: function (dataset) {
this.dataset = dataset;
},
list: function (fields, ifGroups, ifRecords) {
ifRecords(this.dataset);
}
});
instance.web.DataSet = instance.web.CallbackEnabled.extend({
/**
* Collection of OpenERP records, used to share records and the current selection between views.
@@ -774,11 +697,11 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({
if (self._length) {
self._length -= 1;
}
if (this.index !== null) {
if (self.index !== null) {
self.index = self.index <= self.ids.length - 1 ?
self.index : (self.ids.length > 0 ? self.ids.length -1 : 0);
}
this.trigger("dataset_changed", ids, callback, error_callback);
self.trigger("dataset_changed", ids, callback, error_callback);
});
},
size: function () {
+1 -1
View File
@@ -135,7 +135,7 @@ instance.web.format_value = function (value, descriptor, value_if_empty) {
Math.round((value % 1) * 60));
case 'many2one':
// name_get value format
return value[1];
return value[1] ? value[1].split("\n")[0] : value[1];
case 'one2many':
case 'many2many':
if (typeof value === 'string') {
+13 -52
View File
@@ -61,7 +61,7 @@ my.SearchQuery = B.Collection.extend({
this.on('change', function (facet) {
if(!facet.values.isEmpty()) { return; }
this.remove(facet);
this.remove(facet, {silent: true});
}, this);
},
add: function (values, options) {
@@ -324,8 +324,9 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
context: this.dataset.get_context() });
$.when(load_view)
.pipe(this.on_loaded)
.fail(function () {
.pipe(function(r) {
self.search_view_loaded(r)
}).fail(function () {
self.ready.reject.apply(null, arguments);
});
}
@@ -645,7 +646,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
(new instance.web.search.Advanced(this));
},
on_loaded: function(data) {
search_view_loaded: function(data) {
var self = this;
this.fields_view = data.fields_view;
if (data.fields_view.type !== 'search' ||
@@ -654,7 +655,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
"Got non-search view after asking for a search view: type %s, arch root %s",
data.fields_view.type, data.fields_view.arch.tag));
}
this.make_widgets(
data.fields_view['arch'].children,
data.fields_view.fields);
@@ -671,48 +671,12 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
'facet_for_defaults', this.defaults)).then(function () {
self.query.reset(_(arguments).compact(), {preventSearch: true});
});
return $.when(drawer_started, defaults_fetched)
.then(function () { self.ready.resolve(); })
},
/**
* Handle event when the user make a selection in the filters management select box.
*/
on_filters_management: function(e) {
var self = this;
var select = this.$el.find(".oe_search-view-filters-management");
var val = select.val();
switch(val) {
case 'advanced_filter':
this.extended_search.on_activate();
break;
case '':
this.do_clear();
}
if (val.slice(0, 4) == "get:") {
val = val.slice(4);
val = parseInt(val, 10);
var filter = this.managed_filters[val];
this.do_clear(false).then(_.bind(function() {
select.val('get:' + val);
var groupbys = [];
var group_by = filter.context.group_by;
if (group_by) {
groupbys = _.map(
group_by instanceof Array ? group_by : group_by.split(','),
function (el) { return { group_by: el }; });
}
this.filter_data = {
domains: [filter.domain],
contexts: [filter.context],
groupbys: groupbys
};
this.do_search();
}, this));
} else {
select.val('');
}
.then(function () {
self.trigger("search_view_loaded", data);
self.ready.resolve();
});
},
/**
* Extract search data from the view's facets.
@@ -763,7 +727,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
groupbys: groupbys,
errors: errors
};
}, /**
},
/**
* Performs the search view collection of widget data.
*
* If the collection went well (all fields are valid), then triggers
@@ -771,8 +736,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
*
* If at least one field failed its validation, triggers
* :js:func:`instance.web.SearchView.on_invalid` instead.
*
* @param e jQuery event object coming from the "Search" button
*/
do_search: function (_query, options) {
if (options && options.preventSearch) {
@@ -783,7 +746,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
this.on_invalid(search.errors);
return;
}
return this.on_search(search.domains, search.contexts, search.groupbys);
return this.trigger('search_data', search.domains, search.contexts, search.groupbys);
},
/**
* Triggered after the SearchView has collected all relevant domains and
@@ -801,8 +764,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
* @param {Array} contexts an array of literal contexts or context refs
* @param {Array} groupbys ordered contexts which may or may not have group_by keys
*/
on_search: function (domains, contexts, groupbys) {
},
/**
* Triggered after a validation error in the SearchView fields.
*
File diff suppressed because it is too large Load Diff
+70 -14
View File
@@ -64,9 +64,9 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
this.set_groups(new (this.options.GroupsType)(this));
if (this.dataset instanceof instance.web.DataSetStatic) {
this.groups.datagroup = new instance.web.StaticDataGroup(this.dataset);
this.groups.datagroup = new StaticDataGroup(this.dataset);
} else {
this.groups.datagroup = new instance.web.DataGroup(
this.groups.datagroup = new DataGroup(
this, this.model,
dataset.get_domain(),
dataset.get_context());
@@ -83,6 +83,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
});
this.no_leaf = false;
this.on('view_load', self, self.load_list);
},
set_default_options: function (options) {
this._super(options);
@@ -218,7 +219,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
* @param {Object} data.fields_view.arch current list view descriptor
* @param {Boolean} grouped Is the list view grouped
*/
on_loaded: function(data, grouped) {
load_list: function(data, grouped) {
var self = this;
this.fields_view = data;
this.name = "" + this.fields_view.arch.attrs.string;
@@ -358,6 +359,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
this.sidebar.add_toolbar(this.fields_view.toolbar);
this.sidebar.$el.hide();
}
this.trigger('list_view_loaded', data, grouped);
},
/**
* Configures the ListView pager based on the provided dataset's information
@@ -399,14 +401,10 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
*/
setup_columns: function (fields, grouped) {
var registry = instance.web.list.columns;
var reorder = this.options.reorderable;
this.columns.splice(0, this.columns.length);
this.columns.push.apply(this.columns,
_(this.fields_view.arch.children).map(function (field) {
var id = field.attrs.name;
if(field.attrs.widget == 'handle' && !reorder){
field.attrs.reorderable = reorder || true;
}
return registry.for_(id, fields[id], field);
}));
if (grouped) {
@@ -415,8 +413,9 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
}
this.visible_columns = _.filter(this.columns, function (column) {
return column.invisible !== '1' && !column.reorderable;
return column.invisible !== '1';
});
this.aggregate_columns = _(this.visible_columns).invoke('to_aggregate');
},
/**
@@ -471,7 +470,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
reload_view: function (grouped, context, initial) {
var self = this;
var callback = function (field_view_get) {
self.on_loaded(field_view_get, grouped);
self.load_list(field_view_get, grouped);
};
if (this.embedded_view) {
return $.Deferred().then(callback).resolve(this.embedded_view);
@@ -557,7 +556,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
*/
do_search: function (domain, context, group_by) {
this.page = 0;
this.groups.datagroup = new instance.web.DataGroup(
this.groups.datagroup = new DataGroup(
this, this.model, domain, context, group_by);
this.groups.datagroup.sort = this.dataset._sort;
@@ -1153,7 +1152,7 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
passtrough_events: 'action deleted row_link',
/**
* Grouped display for the ListView. Handles basic DOM events and interacts
* with the :js:class:`~instance.web.DataGroup` bound to it.
* with the :js:class:`~DataGroup` bound to it.
*
* Provides events similar to those of
* :js:class:`~instance.web.ListView.List`
@@ -1233,6 +1232,7 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
.replaceWith(self.render());
});
this.$row.children().last()
.addClass('oe_list_group_pagination')
.append($prev)
.append('<span class="oe_list_pager_state"></span>')
.append($next);
@@ -1321,7 +1321,7 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
} catch (e) {
group_label = row_data[group_column.id].value;
}
$group_column.html(_.str.sprintf("%s (%d)",
$group_column.text(_.str.sprintf("%s (%d)",
group_label, group.length));
if (group.length && group.openable) {
@@ -1417,10 +1417,12 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
}))
.end()
.find('button[data-pager-action=previous]')
.attr('disabled', page === 0)
.css('visibility',
page === 0 ? 'hidden' : '')
.end()
.find('button[data-pager-action=next]')
.attr('disabled', page === pages - 1);
.css('visibility',
page === pages - 1 ? 'hidden' : '');
}
}
@@ -1558,6 +1560,60 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
}
});
var DataGroup = instance.web.CallbackEnabled.extend({
init: function(parent, model, domain, context, group_by, level) {
this._super(parent, null);
this.model = new instance.web.Model(model, context, domain);
this.group_by = group_by;
this.context = context;
this.domain = domain;
this.level = level || 0;
},
list: function (fields, ifGroups, ifRecords) {
var self = this;
var query = this.model.query(fields).order_by(this.sort).group_by(this.group_by);
$.when(query).then(function (querygroups) {
// leaf node
if (!querygroups) {
var ds = new instance.web.DataSetSearch(self, self.model.name, self.model.context(), self.model.domain());
ds._sort = self.sort;
ifRecords(ds);
return;
}
// internal node
var child_datagroups = _(querygroups).map(function (group) {
var child_context = _.extend(
{}, self.model.context(), group.model.context());
var child_dg = new DataGroup(
self, self.model.name, group.model.domain(),
child_context, group.model._context.group_by,
self.level + 1);
child_dg.sort = self.sort;
// copy querygroup properties
child_dg.__context = child_context;
child_dg.__domain = group.model.domain();
child_dg.folded = group.get('folded');
child_dg.grouped_on = group.get('grouped_on');
child_dg.length = group.get('length');
child_dg.value = group.get('value');
child_dg.openable = group.get('has_children');
child_dg.aggregates = group.get('aggregates');
return child_dg;
});
ifGroups(child_datagroups);
});
}
});
var StaticDataGroup = DataGroup.extend({
init: function (dataset) {
this.dataset = dataset;
},
list: function (fields, ifGroups, ifRecords) {
ifRecords(this.dataset);
}
});
/**
* @mixin Events
*/
+20 -11
View File
@@ -100,7 +100,7 @@ openerp.web.list_editable = function (instance) {
this._super();
}
},
on_loaded: function (data, grouped) {
load_list: function (data, grouped) {
var self = this;
// tree/@editable takes priority on everything else if present.
var result = this._super(data, grouped);
@@ -190,10 +190,10 @@ openerp.web.list_editable = function (instance) {
this.records.add(record, {
at: this.prepends_on_create() ? 0 : null});
}
var $recordRow = this.groups.get_row_for(record);
var cells = this.get_cells_for($recordRow);
return this.ensure_saved().pipe(function () {
var $recordRow = self.groups.get_row_for(record);
var cells = self.get_cells_for($recordRow);
self.fields_for_resize.splice(0, self.fields_for_resize.length);
return self.with_event('edit', {
record: record.attributes,
@@ -201,10 +201,7 @@ openerp.web.list_editable = function (instance) {
}, function () {
return self.editor.edit(item, function (field_name, field) {
var cell = cells[field_name];
if (!cell || field.get('effective_readonly')) {
// Readonly fields can just remain the list's,
// form's usually don't have backgrounds &al
field.set({invisible: true});
if (!cell) {
return;
}
@@ -254,12 +251,10 @@ openerp.web.list_editable = function (instance) {
var $cell = $(cell);
var position = $cell.position();
// jquery does not understand !important
field.$el.attr('style', 'width: '+$cell.outerWidth()+'px !important');
field.set_dimensions($cell.outerHeight(), $cell.outerWidth());
field.$el.css({
top: position.top,
left: position.left,
minHeight: $cell.outerHeight()
});
},
/**
@@ -400,6 +395,20 @@ openerp.web.list_editable = function (instance) {
},
setup_events: function () {
var self = this;
_.each(this.editor.form.fields, function(field, field_name) {
var setting = false;
var set_invisible = function() {
if (!setting && field.get("effective_readonly")) {
setting = true;
field.set({invisible: true});
setting = false;
}
};
field.on("change:effective_readonly", self, set_invisible);
field.on("change:invisible", self, set_invisible);
set_invisible();
});
this.editor.$el.on('keyup keydown', function (e) {
if (!self.editor.is_editing()) { return; }
var key = _($.ui.keyCode).chain()
@@ -762,7 +771,7 @@ openerp.web.list_editable = function (instance) {
return this._super.apply(this, arguments);
}
var record_id = $(event.currentTarget).data('id');
this.view.start_edition(
return this.view.start_edition(
record_id ? this.records.get(record_id) : null, {
focus_field: $(event.target).data('field')
});
+59 -52
View File
@@ -113,6 +113,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
var item = this.breadcrumbs[index];
item.show(subindex);
this.inner_widget = item.widget;
this.inner_action = item.action;
return true;
},
clear_breadcrumbs: function() {
@@ -131,6 +132,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
if (!dups.length) {
if (this.getParent().has_uncommitted_changes()) {
this.inner_widget = item.widget;
this.inner_action = item.action;
this.breadcrumbs.splice(index, 0, item);
return false;
} else {
@@ -139,7 +141,10 @@ instance.web.ActionManager = instance.web.Widget.extend({
}
}
var last_widget = this.breadcrumbs.slice(-1)[0];
this.inner_widget = last_widget && last_widget.widget;
if (last_widget) {
this.inner_widget = last_widget.widget;
this.inner_action = last_widget.action;
}
},
get_title: function() {
var titles = [];
@@ -234,14 +239,19 @@ instance.web.ActionManager = instance.web.Widget.extend({
}
});
},
do_action: function(action, on_close, clear_breadcrumbs, on_reverse_breadcrumb) {
do_action: function(action, options) {
options = _.defaults(options || {}, {
clear_breadcrumbs: false,
on_reverse_breadcrumb: function() {},
on_close: function() {},
});
if (_.isString(action) && instance.web.client_actions.contains(action)) {
var action_client = { type: "ir.actions.client", tag: action };
return this.do_action(action_client, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return this.do_action(action_client, options);
} else if (_.isNumber(action) || _.isString(action)) {
var self = this;
return self.rpc("/web/action/load", { action_id: action }).pipe(function(result) {
return self.do_action(result, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return self.do_action(result, options);
});
}
if (!action.type) {
@@ -263,7 +273,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
console.error("Action manager can't handle action of type " + action.type, action);
return $.Deferred().reject();
}
return this[type](action, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return this[type](action, options);
},
null_action: function() {
this.dialog_stop();
@@ -276,33 +286,36 @@ instance.web.ActionManager = instance.web.Widget.extend({
* @param {Function<instance.web.Widget>} executor.widget function used to fetch the widget instance
* @param {String} executor.klass CSS class to add on the dialog root, if action.target=new
* @param {Function<instance.web.Widget, undefined>} executor.post_process cleanup called after a widget has been added as inner_widget
* @param on_close
* @param clear_breadcrumbs
* @param {Object} options
* @return {*}
*/
ir_actions_common: function(executor, on_close, clear_breadcrumbs) {
ir_actions_common: function(executor, options) {
if (this.inner_widget && executor.action.target !== 'new') {
if (this.getParent().has_uncommitted_changes()) {
return $.Deferred().reject();
} else if (clear_breadcrumbs) {
} else if (options.clear_breadcrumbs) {
this.clear_breadcrumbs();
}
}
var widget = executor.widget();
if (executor.action.target === 'new') {
if (this.dialog === null) {
// These buttons will be overwrited by <footer> if any
if (this.dialog === null || this.dialog.isDestroyed()) {
this.dialog = new instance.web.Dialog(this, {
buttons: { "Close": function() { $(this).dialog("close"); }},
dialogClass: executor.klass
buttons: {"Close": function() {$(this).dialog("close")}},
dialogClass: executor.klass,
});
if (on_close) {
this.dialog.on("dialog_close", this, on_close);
}
this.dialog.on("closing", null, options.on_close);
this.dialog.init_dialog();
} else {
this.dialog_widget.destroy();
}
this.dialog.dialog_title = executor.action.name;
if (widget instanceof instance.web.ViewManager) {
_.extend(widget.flags, {
$buttons: this.dialog.$buttons,
footer_to_buttons: true,
});
}
this.dialog_widget = widget;
var initialized = this.dialog_widget.appendTo(this.dialog.$el);
this.dialog.open();
@@ -315,24 +328,24 @@ instance.web.ActionManager = instance.web.Widget.extend({
return this.inner_widget.appendTo(this.$el);
}
},
ir_actions_act_window: function (action, on_close, clear_breadcrumbs, on_reverse_breadcrumb) {
ir_actions_act_window: function (action, options) {
var self = this;
return this.ir_actions_common({
widget: function () { return new instance.web.ViewManagerAction(self, action); },
action: action,
klass: 'oe_act_window',
post_process: function (widget) { widget.add_breadcrumb(on_reverse_breadcrumb); }
}, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
post_process: function (widget) { widget.add_breadcrumb(options.on_reverse_breadcrumb); }
}, options);
},
ir_actions_client: function (action, on_close, clear_breadcrumbs, on_reverse_breadcrumb) {
ir_actions_client: function (action, options) {
var self = this;
var ClientWidget = instance.web.client_actions.get_object(action.tag);
if (!(ClientWidget.prototype instanceof instance.web.Widget)) {
var next;
if (next = ClientWidget(this, action.params)) {
return this.do_action(next, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return this.do_action(next, options);
}
return $.when();
}
@@ -345,30 +358,30 @@ instance.web.ActionManager = instance.web.Widget.extend({
self.push_breadcrumb({
widget: widget,
title: action.name,
on_reverse_breadcrumb: on_reverse_breadcrumb,
on_reverse_breadcrumb: options.on_reverse_breadcrumb,
});
if (action.tag !== 'reload') {
self.do_push_state({});
}
}
}, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
}, options);
},
ir_actions_act_window_close: function (action, on_closed) {
if (!this.dialog && on_closed) {
on_closed();
ir_actions_act_window_close: function (action, options) {
if (!this.dialog) {
options.on_close();
}
this.dialog_stop();
},
ir_actions_server: function (action, on_closed, clear_breadcrumbs, on_reverse_breadcrumb) {
ir_actions_server: function (action, options) {
var self = this;
this.rpc('/web/action/run', {
action_id: action.id,
context: action.context || {}
}).then(function (action) {
self.do_action(action, on_closed, clear_breadcrumbs, on_reverse_breadcrumb)
self.do_action(action, options)
});
},
ir_actions_report_xml: function(action, on_closed) {
ir_actions_report_xml: function(action, options) {
var self = this;
instance.web.blockUI();
self.rpc("/web/session/eval_domain_and_context", {
@@ -382,8 +395,8 @@ instance.web.ActionManager = instance.web.Widget.extend({
data: {action: JSON.stringify(action)},
complete: instance.web.unblockUI,
success: function(){
if (!self.dialog && on_closed) {
on_closed();
if (!self.dialog) {
options.on_close();
}
self.dialog_stop();
},
@@ -400,6 +413,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
template: "ViewManager",
init: function(parent, dataset, views, flags) {
this._super(parent);
this.url_states = {};
this.model = dataset ? dataset.model : undefined;
this.dataset = dataset;
this.searchview = null;
@@ -495,13 +509,6 @@ instance.web.ViewManager = instance.web.Widget.extend({
container.hide();
controller.do_hide();
}
// put the <footer> in the dialog's buttonpane
if (self.$el.parent('.ui-dialog-content') && self.$el.find('footer')) {
self.$el.parent('.ui-dialog-content').parent().find('div.ui-dialog-buttonset').hide()
self.$el.find('footer').appendTo(
self.$el.parent('.ui-dialog-content').parent().find('div.ui-dialog-buttonpane')
);
}
}
});
self.trigger('switch_mode', view_type, no_store, view_options);
@@ -571,10 +578,11 @@ instance.web.ViewManager = instance.web.Widget.extend({
action: this.action,
show: function(index) {
var view_to_select = views[index];
self.$el.show();
if (self.active_view !== view_to_select) {
self.switch_mode(view_to_select);
}
var state = self.url_states[view_to_select];
self.do_push_state(state || {});
$.when(self.switch_mode(view_to_select)).then(function() {
self.$el.show();
});
},
get_title: function() {
var id;
@@ -640,7 +648,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
}
this.searchview = new instance.web.SearchView(this, this.dataset, view_id, search_defaults, this.flags.search_view === false);
this.searchview.on_search.add(this.do_searchview_search);
this.searchview.on('search_data', self, this.do_searchview_search);
return this.searchview.appendTo(this.$el.find(".oe_view_manager_view_search"));
},
do_searchview_search: function(domains, contexts, groupbys) {
@@ -912,6 +920,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({
do_push_state: function(state) {
if (this.getParent() && this.getParent().do_push_state) {
state["view_type"] = this.active_view;
this.url_states[this.active_view] = state;
this.getParent().do_push_state(state);
}
},
@@ -1126,11 +1135,13 @@ instance.web.View = instance.web.Widget.extend({
return this.load_view();
},
load_view: function() {
var self = this;
if (this.embedded_view) {
var def = $.Deferred();
var self = this;
$.async_when().then(function() {def.resolve(self.embedded_view);});
return def.pipe(this.on_loaded);
return def.pipe(function(r) {
self.trigger('view_loaded', r);
});
} else {
var context = new instance.web.CompoundContext(this.dataset.get_context());
if (! this.view_type)
@@ -1141,15 +1152,11 @@ instance.web.View = instance.web.Widget.extend({
"view_type": this.view_type,
toolbar: !!this.options.$sidebar,
context: context
}).pipe(this.on_loaded);
}).pipe(function(r) {
self.trigger('view_loaded', r);
});
}
},
/**
* Called after a successful call to fields_view_get.
* Must return a promise.
*/
on_loaded: function(fields_view_get) {
},
set_default_options: function(options) {
this.options = options || {};
_.defaults(this.options, {
+5 -5
View File
@@ -630,10 +630,10 @@
<input type="checkbox" class="oe_list_record_selector"/>
</th>
<t t-foreach="columns" t-as="column">
<th t-if="!column.meta and column.invisible !== '1' and !column.reorderable" t-att-data-id="column.id"
t-attf-class="oe_list_header_#{column.widget or column.type} #{((options.sortable and column.tag !== 'button') ? 'oe_sortable' : null)}">
<th t-if="!column.meta and column.invisible !== '1'" t-att-data-id="column.id"
t-attf-class="oe_list_header_#{column.widget or column.type} #{((options.sortable and column.tag !== 'button') ? 'oe_sortable' : null)}"><div>
<t t-if="column.tag !== 'button'"><t t-esc="column.string"/></t>
</th>
</div></th>
</t>
<th t-if="options.deletable" class="oe_list_record_delete" width="13px"/>
</tr>
@@ -683,7 +683,7 @@
<t t-foreach="columns" t-as="column">
<t t-set="number" t-value="column.type === 'integer' or column.type == 'float'"/>
<t t-set="modifiers" t-value="column.modifiers_for(asData)"/>
<td t-if="!column.meta and column.invisible !== '1' and !column.reorderable" t-att-title="column.help"
<td t-if="!column.meta and column.invisible !== '1'" t-att-title="column.help"
t-attf-class="oe_list_field_cell oe_list_field_#{column.widget or column.type} #{number ? 'oe_number' : ''} #{column.tag === 'button' ? 'oe-button' : ''} #{modifiers.readonly ? 'oe_readonly' : ''} #{modifiers.required ? 'oe_required' : ''}"
t-att-data-field="column.id"
><t t-raw="render_cell(record, column)"/></td>
@@ -1078,7 +1078,7 @@
</t>
<t t-name="FieldStatus.content">
<t t-foreach="widget.selection" t-as="i">
<li t-att-class="i[0] === widget.selected_value ? 'oe_active' : ''" t-att-data-id="i[0]">
<li t-att-class="i[0] === widget.get('value') ? 'oe_active' : ''" t-att-data-id="i[0]">
<span class="label"><t t-esc="i[1]"/></span>
<!-- are you mit ? -->
<span class="arrow"><span></span></span>
+10 -4
View File
@@ -652,7 +652,7 @@ $(document).ready(function () {
}
});
var ds, cs, gs;
view.on_search.add(function (d, c, g) {
view.on('search_data', this, function (d, c, g) {
ds = d, cs = c, gs = g;
});
view.appendTo($fix)
@@ -690,7 +690,7 @@ $(document).ready(function () {
}
}, {dummy: 42});
var ds, cs, gs;
view.on_search.add(function (d, c, g) {
view.on('search_data', this, function (d, c, g) {
ds = d, cs = c, gs = g;
});
view.appendTo($fix)
@@ -718,7 +718,7 @@ $(document).ready(function () {
}
}, {dummy: 42});
var ds;
view.on_search.add(function (d) { ds = d; });
view.on('search_data', this, function (d) { ds = d; });
view.appendTo($fix)
.always(start)
.fail(function (error) { ok(false, error.message); })
@@ -1044,8 +1044,12 @@ $(document).ready(function () {
"second value should be clicked filter");
});
});
asyncTest('click removing from query', 2, function () {
asyncTest('click removing from query', 4, function () {
var calls = 0;
var view = makeSearchView({}, {foo2: true});
view.on('search_data', null, function () {
++calls;
});
var $fix = $('#qunit-fixture');
view.appendTo($fix)
.always(start)
@@ -1054,8 +1058,10 @@ $(document).ready(function () {
var $fs = $fix.find('.oe_searchview_filters ul');
// sanity check
equal(view.query.length, 1, "query should have default facet");
strictEqual(calls, 0);
$fs.children(':eq(1)').trigger('click');
equal(view.query.length, 0, "click should have removed facet");
strictEqual(calls, 1, "one search should have been triggered");
});
});
+2 -2
View File
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
import mock
import unittest2
import web.controllers.main
import openerp.addons.web.controllers.main
class TestDataSetController(unittest2.TestCase):
def setUp(self):
self.dataset = web.controllers.main.DataSet()
self.dataset = openerp.addons.web.controllers.main.DataSet()
self.request = mock.Mock()
self.read = self.request.session.model().read
self.search = self.request.session.model().search
+3 -3
View File
@@ -5,7 +5,7 @@ import mock
import unittest2
import simplejson
import web.controllers.main
import openerp.addons.web.controllers.main
from .. import nonliterals, session as s
def field_attrs(fields_view_get, fieldname):
@@ -16,7 +16,7 @@ def field_attrs(fields_view_get, fieldname):
#noinspection PyCompatibility
class DomainsAndContextsTest(unittest2.TestCase):
def setUp(self):
self.view = web.controllers.main.View()
self.view = openerp.addons.web.controllers.main.View()
def test_convert_literal_domain(self):
e = xml.etree.ElementTree.Element(
@@ -106,7 +106,7 @@ class DomainsAndContextsTest(unittest2.TestCase):
class AttrsNormalizationTest(unittest2.TestCase):
def setUp(self):
self.view = web.controllers.main.View()
self.view = openerp.addons.web.controllers.main.View()
def test_identity(self):
web_view = """
+12 -9
View File
@@ -12,6 +12,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
display_name: _lt('Calendar'),
// Dhtmlx scheduler ?
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.ready = $.Deferred();
this.set_default_options(options);
@@ -38,6 +39,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
this.range_stop = null;
this.update_range_dates(Date.today());
this.selected_filters = [];
this.on('view_loaded', self, self.load_calendar);
},
start: function() {
this._super();
@@ -47,7 +49,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
scheduler.clearAll();
this._super();
},
on_loaded: function(data) {
load_calendar: function(data) {
this.fields_view = data;
this.$el.addClass(this.fields_view.arch.attrs['class']);
this.calendar_fields = {};
@@ -106,7 +108,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
this.sidebar = new instance.web_calendar.Sidebar(this);
this.has_been_loaded.pipe(this.sidebar.appendTo(this.$el.find('.oe_calendar_sidebar_container')));
}
this.trigger('calendar_view_loaded', data);
return this.has_been_loaded.resolve();
},
init_scheduler: function() {
@@ -450,12 +452,19 @@ instance.web_calendar.CalendarFormDialog = instance.web.Dialog.extend({
this.dataset = dataset;
this.view_id = view_id;
this.view = view;
this.on("closing", this, function() {
if (this.view.creating_event_id) {
scheduler.deleteEvent(this.view.creating_event_id);
this.view.creating_event_id = null;
}
});
},
start: function() {
var self = this;
this._super();
this.form = new instance.web.FormView(this, this.dataset, this.view_id, {
pager: false
pager: false,
$buttons: this.$buttons,
});
var def = this.form.appendTo(this.$el);
this.form.on('record_created', self, this.on_form_dialog_saved);
@@ -474,12 +483,6 @@ instance.web_calendar.CalendarFormDialog = instance.web.Dialog.extend({
this.view.reload_event(id);
this.close();
},
on_close: function() {
if (this.view.creating_event_id) {
scheduler.deleteEvent(this.view.creating_event_id);
this.view.creating_event_id = null;
}
}
});
instance.web_calendar.Sidebar = instance.web.Widget.extend({
+12 -7
View File
@@ -11,6 +11,7 @@ instance.web.DiagramView = instance.web.View.extend({
display_name: _lt('Diagram'),
searchable: false,
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.set_default_options(options);
this.view_manager = parent;
@@ -20,17 +21,20 @@ instance.web.DiagramView = instance.web.View.extend({
this.domain = this.dataset._domain || [];
this.context = {};
this.ids = this.dataset.ids;
this.on('view_loaded', self, self.load_diagram);
},
start: function() {
return this.rpc("/web_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded);
var self = this;
return this.rpc("/web_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}).then(function(r) {
self.load_diagram(r);
});
},
toTitleCase: function(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
},
on_loaded: function(result) {
load_diagram: function(result) {
var self = this;
if(this.ids && this.ids.length) {
this.id = this.ids[self.dataset.index || 0];
@@ -47,7 +51,7 @@ instance.web.DiagramView = instance.web.View.extend({
return label.tag == "label";
});
this.$el.html(QWeb.render("DiagramView", {'widget': this}));
this.$el.html(QWeb.render("DiagramView", {'widget': self}));
this.$el.addClass(this.fields_view.arch.attrs['class']);
_.each(self.labels,function(label){
@@ -68,7 +72,7 @@ instance.web.DiagramView = instance.web.View.extend({
if(this.id) {
self.get_diagram_info();
}
this.trigger('diagram_view_loaded', result);
},
get_diagram_info: function() {
@@ -239,7 +243,8 @@ instance.web.DiagramView = instance.web.View.extend({
title: _t("Open: ") + title
}
);
pop.on('on_write_complete', self, function() {
pop.on('write_completed', self, function() {
self.dataset.read_index(_.keys(self.fields_view.fields)).pipe(self.on_diagram_loaded);
});
@@ -303,7 +308,7 @@ instance.web.DiagramView = instance.web.View.extend({
title: _t("Open: ") + title
}
);
pop.on('on_write_complete', self, function() {
pop.on('write_completed', self, function() {
self.dataset.read_index(_.keys(self.fields_view.fields)).pipe(self.on_diagram_loaded);
});
},
+3 -1
View File
@@ -12,11 +12,13 @@ instance.web_gantt.GanttView = instance.web.View.extend({
template: "GanttView",
view_type: "gantt",
init: function() {
var self = this;
this._super.apply(this, arguments);
this.has_been_loaded = $.Deferred();
this.chart_id = _.uniqueId();
this.on('view_loaded', self, self.load_gantt);
},
on_loaded: function(fields_view_get, fields_get) {
load_gantt: function(fields_view_get, fields_get) {
var self = this;
this.fields_view = fields_view_get;
this.$el.addClass(this.fields_view.arch.attrs['class']);
+4 -2
View File
@@ -23,6 +23,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
view_type: "graph",
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.set_default_options(options);
this.dataset = dataset;
@@ -41,6 +42,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this.group_by = [];
this.graph = null;
this.on('view_loaded', self, self.load_graph);
},
destroy: function () {
if (this.graph) {
@@ -49,7 +51,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
this._super();
},
on_loaded: function(fields_view_get) {
load_graph: function(fields_view_get) {
// TODO: move to load_view and document
var self = this;
this.fields_view = fields_view_get;
@@ -98,7 +100,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
self.forcehtml = false;
});
});
return this._super();
this.trigger('graph_view_loaded', fields_view_get);
},
get_format: function (options) {
@@ -7,7 +7,7 @@ openerp.web_hello = function(instance) {
instance.web.SearchView = instance.web.SearchView.extend({
init:function() {
this._super.apply(this,arguments);
this.on_search.add(function(){console.log('hello');});
this.on('search_data', this, function(){console.log('hello');});
}
});
+60 -44
View File
@@ -14,6 +14,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
number_of_color_schemes: 10,
init: function (parent, dataset, view_id, options) {
this._super(parent, dataset, view_id, options);
var self = this;
_.defaults(this.options, {
"quick_creatable": true,
"creatable": true,
@@ -39,8 +40,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this.has_been_loaded = $.Deferred();
this.search_domain = this.search_context = this.search_group_by = null;
this.currently_dragging = {};
this.limit = options.limit || 80;
this.limit = options.limit || 40;
this.add_group_mutex = new $.Mutex();
this.on('view_loaded', self, self.load_kanban);
},
start: function() {
var self = this;
@@ -55,7 +57,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this._super.apply(this, arguments);
$('html').off('click.kanban');
},
on_loaded: function(data) {
load_kanban: function(data) {
this.fields_view = data;
this.$el.addClass(this.fields_view.arch.attrs['class']);
this.$buttons = $(QWeb.render("KanbanView.buttons", {'widget': this}));
@@ -71,7 +73,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this.fields_keys = _.keys(this.fields_view.fields);
this.add_qweb_template();
this.has_been_loaded.resolve();
this._super.apply(this, arguments);
this.trigger('kanban_view_loaded', data);
return $.when();
},
_is_quick_create_enabled: function() {
@@ -194,14 +196,17 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
});
var am = instance.webclient.action_manager;
var form = am.dialog_widget.views.form.controller;
form.on("on_button_cancel", self, am.dialog.on_close);
form.on("on_button_cancel", am.dialog, am.dialog.close);
form.on('record_created', self, function(r) {
(new instance.web.DataSet(self, self.group_by_field.relation)).name_get([r]).then(function(new_record) {
am.dialog.on_close();
am.dialog.close();
var domain = self.dataset.domain.slice(0);
domain.push([self.group_by, '=', new_record[0][0]]);
var dataset = new instance.web.DataSetSearch(self, self.dataset.model, self.dataset.get_context(), domain);
var datagroup = {
get: function(key) {
return this[key];
},
value: new_record[0],
length: 0,
aggregates: {},
@@ -225,21 +230,27 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
self.grouped_by_m2o = (self.group_by_field.type === 'many2one');
self.$buttons.find('.oe_alternative').toggle(self.grouped_by_m2o);
self.$el.toggleClass('oe_kanban_grouped_by_m2o', self.grouped_by_m2o);
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);
var grouping = new instance.web.Model(self.dataset.model, context, domain).query().group_by(self.group_by);
$.when(grouping).then(function(groups) {
if (groups) {
self.do_process_groups(groups);
} else {
self.do_process_dataset();
}
});
});
},
do_process_groups: function(groups) {
var self = this;
this.$el.remove('oe_kanban_ungrouped').addClass('oe_kanban_grouped');
this.$el.removeClass('oe_kanban_ungrouped').addClass('oe_kanban_grouped');
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) {
self.do_clear_groups();
var dataset = new instance.web.DataSetSearch(self, self.dataset.model,
new instance.web.CompoundContext(self.dataset.get_context(), group.context), group.domain);
new instance.web.CompoundContext(self.dataset.get_context(), group.model.context()), group.model.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);
@@ -252,13 +263,13 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}));
});
},
do_process_dataset: function(dataset) {
do_process_dataset: function() {
var self = this;
this.$el.remove('oe_kanban_grouped').addClass('oe_kanban_ungrouped');
this.$el.removeClass('oe_kanban_grouped').addClass('oe_kanban_ungrouped');
this.add_group_mutex.exec(function() {
var def = $.Deferred();
self.do_clear_groups();
self.dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit }).then(function(records) {
self.do_clear_groups();
var kgroup = new instance.web_kanban.KanbanGroup(self, records, null, self.dataset);
self.do_add_groups([kgroup]).then(function() {
if (_.isEmpty(records)) {
@@ -276,23 +287,31 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this.do_search(this.search_domain, this.search_context, this.search_group_by);
},
do_clear_groups: function() {
_.each(this.groups, function(group) {
var groups = this.groups.slice(0);
this.groups = [];
_.each(groups, function(group) {
group.destroy();
});
this.groups = [];
},
do_add_groups: function(groups) {
var self = this;
var $parent = this.$el.parent();
this.$el.detach();
_.each(groups, function(group) {
self.groups[group.undefined_title ? 'unshift' : 'push'](group);
});
var $last_td = self.$el.find('.oe_kanban_groups_headers td:last');
var groups_started = _.map(this.groups, function(group) {
if (!group.is_started) {
return group.insertBefore(self.$el.find('.oe_kanban_groups_headers td:last'));
return group.insertBefore($last_td);
}
});
return $.when.apply(null, groups_started).then(function () {
self.on_groups_started();
self.$el.appendTo($parent);
_.each(self.groups, function(group) {
group.compute_cards_auto_height();
});
});
},
on_groups_started: function() {
@@ -300,8 +319,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this.compute_groups_width();
if (this.group_by) {
// Kanban cards drag'n'drop
this.$el.find('.oe_kanban_column').sortable({
connectWith: '.oe_kanban_column',
var $columns = this.$el.find('.oe_kanban_column');
$columns.sortable({
handle : '.oe_kanban_draghandle',
start: function(event, ui) {
self.currently_dragging.index = ui.item.index();
@@ -312,11 +331,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
ui.placeholder.height(ui.item.height());
},
revert: 150,
beforeStop: function(event,ui){
console.log('beforeStop:',ui);
},
stop: function(event, ui) {
console.log('stop:',ui);
var record = ui.item.data('widget');
var old_index = self.currently_dragging.index;
var new_index = ui.item.index();
@@ -333,6 +348,10 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
},
scroll: false
});
// Keep connectWith out of the sortable initialization for performance sake:
// http://www.planbox.com/blog/development/coding/jquery-ui-sortable-slow-to-bind.html
$columns.sortable({ connectWith: $columns });
// Kanban groups drag'n'drop
var start_index;
if (this.grouped_by_m2o) {
@@ -507,8 +526,8 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
this.aggregates = {};
this.value = this.title = null;
if (this.group) {
this.value = group.value;
this.title = group.value;
this.value = group.get('value');
this.title = group.get('value');
if (this.value instanceof Array) {
this.title = this.value[1];
this.value = this.value[0];
@@ -516,11 +535,11 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
var field = this.view.group_by_field;
if (!_.isEmpty(field)) {
try {
this.title = instance.web.format_value(group.value, field, false);
this.title = instance.web.format_value(group.get('value'), field, false);
} catch(e) {}
}
_.each(this.view.aggregates, function(value, key) {
self.aggregates[value] = group.aggregates[key];
self.aggregates[value] = group.get('aggregates')[key];
});
}
@@ -531,7 +550,7 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
var key = this.view.group_by + '-' + this.value;
if (!this.view.state.groups[key]) {
this.view.state.groups[key] = {
folded: group?group.folded:false
folded: group ? group.get('folded') : false
};
}
this.state = this.view.state.groups[key];
@@ -577,14 +596,13 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
self.quick.focus();
});
// Add bounce effect on image '+' of kanban header when click on empty space of kanban grouped column.
this.$records.find('.oe_kanban_show_more').click(this.do_show_more);
this.$records.on('click', '.oe_kanban_show_more', this.do_show_more);
if (this.state.folded) {
this.do_toggle_fold();
}
this.$el.data('widget', this);
this.$records.data('widget', this);
this.$has_been_started.resolve();
this.compute_cards_auto_height();
var add_btn = this.$el.find('.oe_kanban_add');
add_btn.tipsy({delayIn: 500, delayOut: 1000});
this.$records.click(function (ev) {
@@ -627,18 +645,23 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
},
do_add_records: function(records, prepend) {
var self = this;
var $list_header = this.$records.find('.oe_kanban_group_list_header');
var $show_more = this.$records.find('.oe_kanban_show_more');
_.each(records, function(record) {
var rec = new instance.web_kanban.KanbanRecord(self, record);
if (!prepend) {
rec.insertBefore(self.$records.find('.oe_kanban_show_more'));
rec.insertBefore($show_more);
self.records.push(rec);
} else {
rec.insertAfter($(".oe_kanban_group_list_header", self.$records));
rec.insertAfter($list_header);
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);
if ($show_more.length) {
var size = this.dataset.size();
$show_more.toggle(this.records.length < size).find('.oe_kanban_remaining').text(size - this.records.length);
}
},
remove_record: function(id, remove_from_dataset) {
for (var i = 0; i < this.records.length; i++) {
@@ -660,7 +683,7 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
do_action_edit: function() {
var self = this;
self.do_action({
res_id: this.group.value[0],
res_id: this.value,
name: _t("Edit column"),
res_model: self.view.group_by_field.relation,
views: [[false, 'form']],
@@ -672,16 +695,16 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
});
var am = instance.webclient.action_manager;
var form = am.dialog_widget.views.form.controller;
form.on("on_button_cancel", self, am.dialog.on_close);
form.on("on_button_cancel", am.dialog, am.dialog.close);
form.on('record_saved', self, function() {
am.dialog.on_close();
am.dialog.close();
self.view.do_reload();
});
},
do_action_delete: function() {
var self = this;
if (confirm(_t("Are you sure to remove this column ?"))) {
(new instance.web.DataSet(self, self.view.group_by_field.relation)).unlink([self.group.value[0]]).then(function(r) {
(new instance.web.DataSet(self, self.view.group_by_field.relation)).unlink([self.value]).then(function(r) {
self.view.do_reload();
});
}
@@ -774,13 +797,6 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
bind_events: function() {
var self = this;
this.setup_color_picker();
var $show_on_click = self.$el.find('.oe_kanban_box_show_onclick');
$show_on_click.toggle(this.state.folded);
this.$el.find('.oe_kanban_box_show_onclick_trigger').click(function() {
$show_on_click.toggle();
self.state.folded = !self.state.folded;
});
this.$el.find('[tooltip]').tipsy({
delayIn: 500,
delayOut: 0,
@@ -47,7 +47,7 @@
<div class="oe_fold_column">
<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 oe_tag" style="position:relative; top:-2px;"><t t-esc="widget.group.length"/></span>
<span class="oe_kanban_group_length oe_tag" style="position:relative; top:-2px;"><t t-esc="widget.group.get('length')"/></span>
</div>
<ul class="oe_kanban_aggregates">
<li t-foreach="widget.aggregates" t-as="aggregate">
@@ -67,13 +67,14 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({
{text: _t("Close"), click: function() { self.view_edit_dialog.close(); window.location.reload(); }}
]
}).open();
this.view_edit_dialog.on("closing", this, function(){window.location.reload();});
this.main_view_id = this.parent.fields_view.view_id;
this.action_manager = new instance.web.ActionManager(this);
this.action_manager.appendTo(this.view_edit_dialog.$el);
$.when(this.action_manager.do_action(action)).then(function() {
var viewmanager = self.action_manager.inner_widget;
var controller = viewmanager.views[viewmanager.active_view].controller;
controller.on_loaded.add_last(function(){
controller.on('view_loaded', function(){
$(controller.groups).bind({
'selected': function(e, ids, records) {
self.main_view_id = ids[0];