diff options
| author | Rucha (Open ERP) <rpa@tinyerp.com> | 2012-08-13 10:44:11 +0530 |
|---|---|---|
| committer | Rucha (Open ERP) <rpa@tinyerp.com> | 2012-08-13 10:44:11 +0530 |
| commit | dd7a2972d8099fdc8ccb17ee6b7a56a4be2bbb1f (patch) | |
| tree | 255b0bb9cba8bd5ecd542db5ed3fdc79a004cba0 /addons/board/static/src | |
| parent | 7739d0d69b856c3eca8282e52100a06fe6ab2ff3 (diff) | |
| parent | 9211174a6fbbec8d2637c7d9295714c1657dd8ee (diff) | |
[MERGE]: Merge with latest trunk-addons
bzr revid: rpa@tinyerp.com-20120813051411-5no0xcudwbkw07c5
Diffstat (limited to 'addons/board/static/src')
| -rw-r--r-- | addons/board/static/src/css/dashboard.css | 73 | ||||
| -rw-r--r-- | addons/board/static/src/css/dashboard.sass | 83 | ||||
| -rw-r--r-- | addons/board/static/src/img/layout_1-1-1.png | bin | 0 -> 306 bytes | |||
| -rw-r--r-- | addons/board/static/src/img/layout_1-1.png | bin | 0 -> 313 bytes | |||
| -rw-r--r-- | addons/board/static/src/img/layout_1-2.png | bin | 0 -> 313 bytes | |||
| -rw-r--r-- | addons/board/static/src/img/layout_1.png | bin | 0 -> 292 bytes | |||
| -rw-r--r-- | addons/board/static/src/img/layout_2-1.png | bin | 0 -> 304 bytes | |||
| -rw-r--r-- | addons/board/static/src/img/view_todo_arrow.png | bin | 0 -> 3389 bytes | |||
| -rw-r--r-- | addons/board/static/src/js/dashboard.js | 378 | ||||
| -rw-r--r-- | addons/board/static/src/xml/board.xml | 80 |
10 files changed, 614 insertions, 0 deletions
diff --git a/addons/board/static/src/css/dashboard.css b/addons/board/static/src/css/dashboard.css new file mode 100644 index 00000000000..f3d300add2e --- /dev/null +++ b/addons/board/static/src/css/dashboard.css @@ -0,0 +1,73 @@ +.openerp .oe_dashboard_links { + text-align: right; + margin: 0 4px 6px 0; +} +.openerp .oe_dashboard { + width: 100%; +} +.openerp .oe_dashboard .oe_action { + margin: 0 8px 8px 0; + background-color: white; + border: 1px solid; + border-color: #e5e5e5 #dbdbdb #d2d2d2; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + -moz-box-shadow: 0 0 2px rgba(0, 0, 0, 0.2); + -webkit-box-shadow: 0 0 2px rgba(0, 0, 0, 0.2); + box-shadow: 0 0 2px rgba(0, 0, 0, 0.2); +} +.openerp .oe_dashboard .oe_action .oe_header { + font-size: 16px; + vertical-align: middle; + margin: 0; + padding: 12px; + -moz-border-radius: 3px 3px 0 0; + -webkit-border-radius: 3px 3px 0 0; + border-radius: 3px 3px 0 0; +} +.openerp .oe_dashboard .oe_action .oe_header:hover { + cursor: move; +} +.openerp .oe_dashboard .oe_action .oe_header .oe_icon { + float: right; + cursor: pointer; + color: #b3b3b3; +} +.openerp .oe_dashboard .oe_action .oe_header .oe_icon:hover { + color: #666666; + text-decoration: none; +} +.openerp .oe_dashboard .oe_action .oe_header .oe_close:after { + content: "×"; + margin-left: 4px; +} +.openerp .oe_dashboard .oe_action .oe_header .oe_minimize:after { + content: "-"; + margin-left: 4px; +} +.openerp .oe_dashboard .oe_action .oe_header .oe_maximize:after { + content: "+"; + margin-left: 4px; +} +.openerp .oe_dashboard .oe_action .oe_header_empty { + padding-top: 0; + padding-bottom: 2px; +} +.openerp .oe_dashboard .oe_action .oe_button_create { + margin-left: 4px; + padding: 0 4px 0 4px; + height: 16px !important; +} +.openerp .oe_dashboard .oe_action .oe_content { + padding: 0 12px 12px 12px; +} +.openerp .oe_dashboard .oe_action .oe_content .oe_view_manager_header { + display: none; +} +.openerp .oe_dashboard .oe_action .oe_content .oe_list_content > thead { + border-bottom: 1px; +} +.openerp .oe_dashboard .oe_action .oe_content .oe_list_content > tbody tr:nth-child(odd) { + background: transparent; +} diff --git a/addons/board/static/src/css/dashboard.sass b/addons/board/static/src/css/dashboard.sass new file mode 100644 index 00000000000..dd4d144e918 --- /dev/null +++ b/addons/board/static/src/css/dashboard.sass @@ -0,0 +1,83 @@ +@mixin radius($radius: 5px) + -moz-border-radius: $radius + -webkit-border-radius: $radius + border-radius: $radius + +@mixin box-shadow($bsval: 0px 1px 4px #777) + -moz-box-shadow: $bsval + -webkit-box-shadow: $bsval + box-shadow: $bsval + +.openerp + .oe_dashboard_links + text-align: right + margin: 0 4px 6px 0 + .oe_dashboard + width: 100% + .oe_action + margin: 0 8px 8px 0 + background-color: white + border: 1px solid + border-color: #e5e5e5 #dbdbdb #d2d2d2 + @include radius(3px) + @include box-shadow(0 0 2px rgba(0,0,0,0.2)) + .oe_header + font-size: 16px + vertical-align: middle + margin: 0 + padding: 12px + @include radius(3px 3px 0 0) + + //border-bottom: 1px dotted #dbdbdb + //@include radius(2px 2px 0 0) + //@include vertical-gradient(#FCFCFC, #DEDEDE) + &:hover + cursor: move + .oe_icon + float: right + cursor: pointer + color: #b3b3b3 + &:hover + color: #666 + text-decoration: none + .oe_close:after + content: "×" + margin-left: 4px + .oe_minimize:after + content: "-" + margin-left: 4px + .oe_maximize:after + content: "+" + margin-left: 4px + .oe_header_empty + padding-top: 0 + padding-bottom: 2px + .oe_button_create + margin-left: 4px + padding: 0 4px 0 4px + height: 16px !important + //.oe_rename + //float: left + //padding-right: 4px + //position: relative + //top: 1px + //.oe_input + //height: 16px; + //position: relative; + //top: 2px; + //.ui-sortable-placeholder + //border: 1px dotted black; + //visibility: visible !important; + //height: 50px !important; + //* + //visibility: hidden; + .oe_content + padding: 0 12px 12px 12px + .oe_view_manager_header + display: none + .oe_list_content + > thead + border-bottom: 1px + > tbody + tr:nth-child(odd) + background: transparent diff --git a/addons/board/static/src/img/layout_1-1-1.png b/addons/board/static/src/img/layout_1-1-1.png Binary files differnew file mode 100644 index 00000000000..5eda2823c46 --- /dev/null +++ b/addons/board/static/src/img/layout_1-1-1.png diff --git a/addons/board/static/src/img/layout_1-1.png b/addons/board/static/src/img/layout_1-1.png Binary files differnew file mode 100644 index 00000000000..e72aa3a0533 --- /dev/null +++ b/addons/board/static/src/img/layout_1-1.png diff --git a/addons/board/static/src/img/layout_1-2.png b/addons/board/static/src/img/layout_1-2.png Binary files differnew file mode 100644 index 00000000000..4b14d7aeaad --- /dev/null +++ b/addons/board/static/src/img/layout_1-2.png diff --git a/addons/board/static/src/img/layout_1.png b/addons/board/static/src/img/layout_1.png Binary files differnew file mode 100644 index 00000000000..69a0e30854c --- /dev/null +++ b/addons/board/static/src/img/layout_1.png diff --git a/addons/board/static/src/img/layout_2-1.png b/addons/board/static/src/img/layout_2-1.png Binary files differnew file mode 100644 index 00000000000..ed866add47c --- /dev/null +++ b/addons/board/static/src/img/layout_2-1.png diff --git a/addons/board/static/src/img/view_todo_arrow.png b/addons/board/static/src/img/view_todo_arrow.png Binary files differnew file mode 100644 index 00000000000..8633430e9ae --- /dev/null +++ b/addons/board/static/src/img/view_todo_arrow.png diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/dashboard.js new file mode 100644 index 00000000000..b9df81bf868 --- /dev/null +++ b/addons/board/static/src/js/dashboard.js @@ -0,0 +1,378 @@ +openerp.board = function(instance) { +var QWeb = instance.web.qweb, + _t = instance.web._t; + +if (!instance.board) { + /** @namespace */ + instance.board = {}; +} + +instance.web.form.DashBoard = instance.web.form.FormWidget.extend({ + init: function(view, node) { + this._super(view, node); + this.form_template = 'DashBoard'; + this.actions_attrs = {}; + this.action_managers = []; + }, + start: function() { + var self = this; + this._super.apply(this, arguments); + + this.$element.find('.oe_dashboard_column').sortable({ + connectWith: '.oe_dashboard_column', + handle: '.oe_header', + scroll: false + }).disableSelection().bind('sortstop', self.do_save_dashboard); + + // Events + this.$element.find('.oe_dashboard_link_reset').click(this.on_reset); + this.$element.find('.oe_dashboard_link_change_layout').click(this.on_change_layout); + + this.$element.delegate('.oe_dashboard_column .oe_fold', 'click', this.on_fold_action); + this.$element.delegate('.oe_dashboard_column .oe_close', 'click', this.on_close_action); + + // Init actions + _.each(this.node.children, function(column, column_index) { + _.each(column.children, function(action, action_index) { + delete(action.attrs.width); + delete(action.attrs.height); + delete(action.attrs.colspan); + var action_id = _.str.toNumber(action.attrs.name); + if (!_.isNaN(action_id)) { + self.rpc('/web/action/load', {action_id: action_id}, function(result) { + self.on_load_action(result, column_index + '_' + action_index, action.attrs); + }); + } + }); + }); + }, + on_reset: function() { + this.rpc('/web/view/undo_custom', { + view_id: this.view.fields_view.view_id, + reset: true + }, this.do_reload); + }, + on_change_layout: function() { + var self = this; + var qdict = { + current_layout : this.$element.find('.oe_dashboard').attr('data-layout') + }; + var $dialog = instance.web.dialog($('<div>'), { + modal: true, + title: _t("Edit Layout"), + width: 'auto', + height: 'auto' + }).html(QWeb.render('DashBoard.layouts', qdict)); + $dialog.find('li').click(function() { + var layout = $(this).attr('data-layout'); + $dialog.dialog('destroy'); + self.do_change_layout(layout); + }); + }, + do_change_layout: function(new_layout) { + var $dashboard = this.$element.find('.oe_dashboard'); + var current_layout = $dashboard.attr('data-layout'); + if (current_layout != new_layout) { + var clayout = current_layout.split('-').length, + nlayout = new_layout.split('-').length, + column_diff = clayout - nlayout; + if (column_diff > 0) { + var $last_column = $(); + $dashboard.find('.oe_dashboard_column').each(function(k, v) { + if (k >= nlayout) { + $(v).find('.oe_action').appendTo($last_column); + } else { + $last_column = $(v); + } + }); + } + $dashboard.toggleClass('oe_dashboard_layout_' + current_layout + ' oe_dashboard_layout_' + new_layout); + $dashboard.attr('data-layout', new_layout); + this.do_save_dashboard(); + } + }, + on_fold_action: function(e) { + var $e = $(e.currentTarget), + $action = $e.parents('.oe_action:first'), + id = parseInt($action.attr('data-id'), 10); + if ($e.is('.oe_minimize')) { + $action.data('action_attrs').fold = '1'; + } else { + delete($action.data('action_attrs').fold); + } + $e.toggleClass('oe_minimize oe_maximize'); + $action.find('.oe_content').toggle(); + this.do_save_dashboard(); + }, + on_close_action: function(e) { + if (confirm(_t("Are you sure you want to remove this item ?"))) { + $(e.currentTarget).parents('.oe_action:first').remove(); + this.do_save_dashboard(); + } + }, + do_save_dashboard: function() { + var self = this; + var board = { + form_title : this.view.fields_view.arch.attrs.string, + style : this.$element.find('.oe_dashboard').attr('data-layout'), + columns : [] + }; + this.$element.find('.oe_dashboard_column').each(function() { + var actions = []; + $(this).find('.oe_action').each(function() { + var action_id = $(this).attr('data-id'), + new_attrs = _.clone($(this).data('action_attrs')); + if (new_attrs.domain) { + new_attrs.domain = new_attrs.domain_string; + delete(new_attrs.domain_string); + } + if (new_attrs.context) { + new_attrs.context = new_attrs.context_string; + delete(new_attrs.context_string); + } + actions.push(new_attrs); + }); + board.columns.push(actions); + }); + var arch = QWeb.render('DashBoard.xml', board); + this.rpc('/web/view/add_custom', { + view_id: this.view.fields_view.view_id, + arch: arch + }, function() { + self.$element.find('.oe_dashboard_link_reset').show(); + }); + }, + on_load_action: function(result, index, action_attrs) { + var self = this, + action = result.result, + view_mode = action_attrs.view_mode; + + if (action_attrs.context && action_attrs.context['dashboard_merge_domains_contexts'] === false) { + // TODO: replace this 6.1 workaround by attribute on <action/> + action.context = action_attrs.context || {}; + action.domain = action_attrs.domain || []; + } else { + if (action_attrs.context) { + action.context = _.extend((action.context || {}), action_attrs.context); + } + if (action_attrs.domain) { + action.domain = action.domain || []; + action.domain.unshift.apply(action.domain, action_attrs.domain); + } + } + + var action_orig = _.extend({ flags : {} }, action); + + if (view_mode && view_mode != action.view_mode) { + action.views = _.map(view_mode.split(','), function(mode) { + mode = mode === 'tree' ? 'list' : mode; + return _(action.views).find(function(view) { return view[1] == mode; }) + || [false, mode]; + }); + } + + action.flags = { + search_view : false, + sidebar : false, + views_switcher : false, + action_buttons : false, + pager: false, + low_profile: true, + display_title: false, + list: { + selectable: false + } + }; + var am = new instance.web.ActionManager(this), + // FIXME: ideally the dashboard view shall be refactored like kanban. + $action = $('#' + this.view.element_id + '_action_' + index); + $action.parent().data('action_attrs', action_attrs); + this.action_managers.push(am); + am.appendTo($action); + am.do_action(action); + am.do_action = function (action) { + self.do_action(action); + }; + if (action_attrs.creatable && action_attrs.creatable !== 'false') { + var action_id = parseInt(action_attrs.creatable, 10); + $action.parent().find('button.oe_dashboard_button_create').click(function() { + if (isNaN(action_id)) { + action_orig.flags.default_view = 'form'; + self.do_action(action_orig); + } else { + self.rpc('/web/action/load', { + action_id: action_id + }, function(result) { + result.result.flags = result.result.flags || {}; + result.result.flags.default_view = 'form'; + self.do_action(result.result); + }); + } + }); + } + if (am.inner_widget) { + am.inner_widget.on_mode_switch.add(function(mode) { + var new_views = []; + _.each(action_orig.views, function(view) { + new_views[view[1] === mode ? 'unshift' : 'push'](view); + }); + if (!new_views.length || new_views[0][1] !== mode) { + new_views.unshift([false, mode]); + } + action_orig.views = new_views; + action_orig.res_id = am.inner_widget.dataset.ids[am.inner_widget.dataset.index]; + self.do_action(action_orig); + }); + } + }, + renderElement: function() { + this._super(); + + var check = _.detect(this.node.children, function(column, column_index) { + return _.detect(column.children,function(element){ + return element.tag === "action"? element: false; + }); + }); + if (!check) { + return this.no_result(); + } + // We should start with three columns available + for (var i = this.node.children.length; i < 3; i++) { + this.node.children.push({ + tag: 'column', + attrs: {}, + children: [] + }); + } + var rendered = QWeb.render(this.form_template, this); + this.$element.html(rendered); + }, + no_result: function() { + if (this.view.options.action.help) { + this.$element.append( + $('<div class="oe_view_nocontent">') + .append($('<div>').html(this.view.options.action.help || " ")) + ); + } + }, + do_reload: function() { + var view_manager = this.view.getParent(), + action_manager = view_manager.getParent(); + this.view.destroy(); + action_manager.do_action(view_manager.action); + } +}); +instance.web.form.DashBoardLegacy = instance.web.form.DashBoard.extend({ + renderElement: function() { + if (this.node.tag == 'hpaned') { + this.node.attrs.style = '2-1'; + } else if (this.node.tag == 'vpaned') { + this.node.attrs.style = '1'; + } + this.node.tag = 'board'; + _.each(this.node.children, function(child) { + if (child.tag.indexOf('child') == 0) { + child.tag = 'column'; + var actions = [], first_child = child.children[0]; + if (first_child && first_child.tag == 'vpaned') { + _.each(first_child.children, function(subchild) { + actions.push.apply(actions, subchild.children); + }); + child.children = actions; + } + } + }); + this._super(this); + } +}); + +instance.web.form.tags.add('hpaned', 'instance.web.form.DashBoardLegacy'); +instance.web.form.tags.add('vpaned', 'instance.web.form.DashBoardLegacy'); +instance.web.form.tags.add('board', 'instance.web.form.DashBoard'); + + +instance.board.AddToDashboard = instance.web.search.Input.extend({ + template: 'SearchView.addtodashboard', + _in_drawer: true, + start: function () { + var self = this; + this.$element + .on('click', 'h4', this.proxy('show_option')) + .on('submit', 'form', function (e) { + e.preventDefault(); + self.add_dashboard(); + }); + return this.load_data().then(this.proxy("render_data")); + }, + load_data:function(){ + var board = new instance.web.Model('board.board'); + return board.call('list'); + }, + _x:function() { + if (!instance.webclient) { return $.Deferred().reject(); } + var dashboard_menu = instance.webclient.menu.data.data.children; + return new instance.web.Model('ir.model.data') + .query(['res_id']) + .filter([['name','=','menu_reporting_dashboard']]) + .first().pipe(function (result) { + var menu = _(dashboard_menu).chain() + .pluck('children') + .flatten(true) + .find(function (child) { return child.id === result.res_id; }) + .value(); + return menu ? menu.children : []; + }); + }, + render_data: function(dashboard_choices){ + var selection = instance.web.qweb.render( + "SearchView.addtodashboard.selection", { + selections: dashboard_choices}); + this.$("input").before(selection) + }, + add_dashboard: function(){ + var self = this; + var getParent = this.getParent(); + var view_parent = this.getParent().getParent(); + if (! view_parent.action || ! this.$element.find("select").val()) { + this.do_warn("Can't find dashboard action"); + return; + } + var data = getParent.build_search_data(); + var context = new instance.web.CompoundContext(getParent.dataset.get_context() || []); + var domain = new instance.web.CompoundDomain(getParent.dataset.get_domain() || []); + _.each(data.contexts, context.add, context); + _.each(data.domains, domain.add, domain); + this.rpc('/board/add_to_dashboard', { + menu_id: this.$element.find("select").val(), + action_id: view_parent.action.id, + context_to_save: context, + domain: domain, + view_mode: view_parent.active_view, + name: this.$element.find("input").val() + }, function(r) { + if (r === false) { + self.do_warn("Could not add filter to dashboard"); + } else { + self.$element.toggleClass('oe_opened'); + self.do_notify("Filter added to dashboard", ''); + } + }); + }, + show_option:function(){ + this.$element.toggleClass('oe_opened'); + if (! this.$element.hasClass('oe_opened')) + return; + this.$("input").val(this.getParent().fields_view.name || "" ); + } +}); + + +instance.web.SearchView.include({ + add_common_inputs: function() { + this._super(); + (new instance.board.AddToDashboard(this)); + + } +}); + +}; diff --git a/addons/board/static/src/xml/board.xml b/addons/board/static/src/xml/board.xml new file mode 100644 index 00000000000..13d81d11f8d --- /dev/null +++ b/addons/board/static/src/xml/board.xml @@ -0,0 +1,80 @@ +<template> +<t t-name="DashBoard"> + <div class="oe_dashboard_links"> + <button type="button" class="button oe_dashboard_link_reset" title="Reset Layout.." t-att-style="view.fields_view.custom_view_id ? null : 'display: none'"> + <img src="/board/static/src/img/layout_2-1.png" width="16" height="16"/> + <span> Reset </span> + </button> + <button type="button" class="button oe_dashboard_link_change_layout" title="Change Layout.."> + <img src="/board/static/src/img/layout_1-1-1.png" width="16" height="16"/> + <span> Change Layout </span> + </button> + </div> + <table t-att-data-layout="node.attrs.style" t-attf-class="oe_dashboard oe_dashboard_layout_#{node.attrs.style}" cellspacing="0" cellpadding="0" border="0"> + <tr> + <td t-foreach="node.children" t-as="column" t-if="column.tag == 'column'" + t-att-id="view.element_id + '_column_' + column_index" t-attf-class="oe_dashboard_column index_#{column_index}"> + + <t t-foreach="column.children" t-as="action" t-if="action.tag == 'action'" t-call="DashBoard.action"/> + </td> + </tr> + </table> +</t> +<t t-name="DashBoard.action"> + <div t-att-data-id="action.attrs.name" class="oe_action"> + <h2 t-attf-class="oe_header #{action.attrs.string ? '' : 'oe_header_empty'}"> + <t t-esc="action.attrs.string"/> + <t t-if="!action.attrs.string">&nbsp;</t> + <button t-if="action.attrs.creatable and action.attrs.creatable !== 'false'" class="oe_button oe_button_create">Create</button> + <span class='oe_icon oe_close'></span> + <span class='oe_icon oe_minimize oe_fold' t-if="!action.attrs.fold"></span> + <span class='oe_icon oe_maximize oe_fold' t-if="action.attrs.fold"></span> + </h2> + <div t-attf-id="#{view.element_id}_action_#{column_index}_#{action_index}" class="oe_content" t-att-style="action.attrs.fold ? 'display: none' : null"></div> + </div> +</t> +<t t-name="DashBoard.layouts"> + <div class="oe_dashboard_layout_selector"> + <p> + <strong>Choose dashboard layout</strong> + </p> + <ul> + <li t-foreach="'1 1-1 1-1-1 1-2 2-1'.split(' ')" t-as="layout" t-att-data-layout="layout"> + <img t-attf-src="/board/static/src/img/layout_#{layout}.png"/> + <img t-if="layout == current_layout" + src="/web/static/src/img/icons/gtk-apply.png" width="16" height="16" class="oe_dashboard_selected_layout"/> + </li> + </ul> + </div> +</t> +<t t-name="DashBoard.xml"> + <form t-att-string="form_title" version="7.0"> + <board t-att-style="style"> + <column t-foreach="columns" t-as="column"> + <action t-foreach="column" t-as="action" t-att="action"/> + </column> + </board> + </form> +</t> +<div t-name="HomeWidget" class="oe_dashboard_home_widget"/> +<t t-name="HomeWidget.content"> + <h3><t t-esc="widget.title"/></h3> + <iframe width="100%" frameborder="0" t-att-src="url"/> +</t> + +<div t-name="SearchView.addtodashboard" class="oe_searchview_dashboard"> + <h4>Add to Dashboard</h4> + <form> + <p><input placeholder="Title of new dashboard item"/></p> + <button class="oe_apply" type="submit">Add</button> + </form> +</div> +<t t-name="SearchView.addtodashboard.selection"> + <select> + <option t-foreach="selections" t-as="element" + t-att-value="element.id "> + <t t-esc="element.name"/></option> + </select> +</t> + +</template> |
