From a5de0394098faf3554ae4e76303569eb49686059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 6 Mar 2015 09:33:35 +0100 Subject: [PATCH] Manage bookmarks review13021002 --- src/common.js | 72 +++++++++++++++++++++++ src/sao.js | 1 + src/screen.js | 158 +++++++++++++++++++++++++++++++++++++++++++++----- tests/sao.js | 17 ++++++ 4 files changed, 234 insertions(+), 14 deletions(-) diff --git a/src/common.js b/src/common.js index 4b6c28fabc..2d84dcf69e 100644 --- a/src/common.js +++ b/src/common.js @@ -409,6 +409,52 @@ }); Sao.common.MODELHISTORY = new Sao.common.ModelHistory(); + Sao.common.ViewSearch = Sao.class_(Object, { + load_searches: function() { + this.searches = {}; + return Sao.rpc({ + 'method': 'model.ir.ui.view_search.get_search', + 'params': [{}] + }, Sao.Session.current_session).then(function(searches) { + this.searches = searches; + }.bind(this)); + }, + get: function(model) { + return this.searches[model] || []; + }, + add: function(model, name, domain) { + return Sao.rpc({ + 'method': 'model.ir.ui.view_search.create', + 'params': [[{ + 'model': model, + 'name': name, + 'domain': new Sao.PYSON.Encoder().encode(domain) + }], {}] + }, Sao.Session.current_session).then(function(ids) { + var id = ids[0]; + if (this.searches[model] === undefined) { + this.searches[model] = []; + } + this.searches[model].push([id, name, domain]); + }.bind(this)); + }, + remove: function(model, id) { + return Sao.rpc({ + 'method': 'model.ir.ui.view_search.delete', + 'params': [[id], {}] + }, Sao.Session.current_session).then(function() { + for (var i = 0; i < this.searches[model].length; i++) { + var domain = this.searches[model][i]; + if (domain[0] === id) { + this.searches[model].splice(i, 1); + break; + } + } + }.bind(this)); + } + }); + Sao.common.VIEW_SEARCH = new Sao.common.ViewSearch(); + Sao.common.humanize = function(size) { var sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']; for (var i =0, len = sizes.length; i < len; i++) { @@ -844,6 +890,32 @@ throw e; } }, + stringable: function(domain) { + var stringable_ = function(clause) { + if (!clause) { + return true; + } + var is_array = function(e) { + return e instanceof Array; + }; + if ((~['AND', 'OR'].indexOf(clause[0]) || + (is_array(clause[0]))) && + clause.slice(1).every(is_array)) { + return this.stringable(clause); + } + if ((clause[0] in this.fields) || clause[0] == 'rec_name') { + return true; + } + return false; + }.bind(this); + if (!domain) { + return true; + } + if (~['AND', 'OR'].indexOf(domain[0])) { + domain = domain.slice(1); + } + return domain.every(stringable_); + }, string: function(domain) { var string = function(clause) { diff --git a/src/sao.js b/src/sao.js index b2470f66a6..5425bbea9f 100644 --- a/src/sao.js +++ b/src/sao.js @@ -151,6 +151,7 @@ var Sao = {}; deferreds.push(Sao.common.MODELACCESS.load_models()); deferreds.push(Sao.common.ICONFACTORY.load_icons()); deferreds.push(Sao.common.MODELHISTORY.load_history()); + deferreds.push(Sao.common.VIEW_SEARCH.load_searches()); return jQuery.when.apply(jQuery, deferreds).then(function() { (preferences.actions || []).forEach(function(action_id) { Sao.Action.execute(action_id, {}, null, {}); diff --git a/src/screen.js b/src/screen.js index 966f800f74..67096c2ae1 100644 --- a/src/screen.js +++ b/src/screen.js @@ -25,18 +25,45 @@ }).append('Filters'); // TODO translation this.filter_button.click(this.search_box.bind(this)); this.search_entry = jQuery('', { - 'class': 'form-control' + 'class': 'form-control', + 'placeholder': 'Search' }); - this.search_entry.keypress(function(e) { - if (e.which == 13) { - this.do_search(); - return false; - } - }.bind(this)); + this.search_entry.keypress(this.key_press.bind(this)); this.but_bookmark = jQuery('