Jiten (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-add_to_dashboard-vme into lp:openerp-web.

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-add_to_dashboard-vme/+merge/109124

Add to Dashboard
----------------
* This is the feature "Add to Dashboard" for trunk web which is missing after 
6.1. 
So, now dynamically user can add dashboard.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-add_to_dashboard-vme/+merge/109124
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-add_to_dashboard-vme.
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py	2012-05-15 07:05:56 +0000
+++ addons/web/controllers/main.py	2012-06-07 12:29:23 +0000
@@ -1286,14 +1286,29 @@
                 del filter['context']
                 del filter['domain']
         return filters
-
+    
+    @openerpweb.jsonrequest
+    def get_all_dashboard(self, req):
+         all_dashboard = []
+         Model = req.session.model('ir.actions.act_window')
+         Dashboard_Menus = req.session.model('ir.values')
+         Dashboard_act_window = Model.search_read([('res_model','=',"board.board"), ('view_id','!=', False) ],['name','id'])
+         for i in Dashboard_act_window:
+             tuple_of_dashboard = "ir.actions.act_window," + str(i["id"])
+             menu_id = Dashboard_Menus.search_read([('value','=',tuple_of_dashboard)],['res_id'])
+             if menu_id:
+                all_dashboard.append({"res_id":menu_id[0]["res_id"],"name":i["name"]})
+         return all_dashboard
+     
     @openerpweb.jsonrequest
     def add_to_dashboard(self, req, menu_id, action_id, context_to_save, domain, view_mode, name=''):
-        ctx = common.nonliterals.CompoundContext(context_to_save)
-        ctx.session = req.session
-        ctx = ctx.evaluate()
+        to_eval = common.nonliterals.CompoundContext(context_to_save)
+        to_eval.session = req.session
+        ctx = dict((k, v) for k, v in to_eval.evaluate().iteritems()
+                   if not k.startswith('search_default_'))
         ctx['dashboard_merge_domains_contexts'] = False # TODO: replace this 6.1 workaround by attribute on <action/>
         domain = common.nonliterals.CompoundDomain(domain)
+        print "domainnnnn",domain
         domain.session = req.session
         domain = domain.evaluate()
 

=== modified file 'addons/web/static/src/css/base.css'
--- addons/web/static/src/css/base.css	2012-06-07 09:29:02 +0000
+++ addons/web/static/src/css/base.css	2012-06-07 12:29:23 +0000
@@ -1456,6 +1456,20 @@
   top: 0;
   right: 5px;
 }
+.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_dashboard form {
+  display: none;
+  margin-top: 2px;
+}
+.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_dashboard ul {
+  list-style: none;
+  padding: 0;
+}
+.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_dashboard li {
+  position: relative;
+  list-style: none;
+  margin: 0;
+  white-space: nowrap;
+}
 .openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced form {
   display: none;
   margin-top: 8px;

=== modified file 'addons/web/static/src/css/base.sass'
--- addons/web/static/src/css/base.sass	2012-06-07 09:29:02 +0000
+++ addons/web/static/src/css/base.sass	2012-06-07 12:29:23 +0000
@@ -1145,6 +1145,18 @@
                         position: absolute
                         top: 0
                         right: 5px
+            .oe_searchview_dashboard
+                form
+                    display: none
+                    margin-top: 2px
+                ul
+                    list-style: none
+                    padding: 0
+                li
+                    position: relative
+                    list-style: none
+                    margin: 0
+                    white-space: nowrap
             .oe_searchview_advanced
                 form
                     display: none

=== modified file 'addons/web/static/src/js/search.js'
--- addons/web/static/src/js/search.js	2012-06-06 13:10:42 +0000
+++ addons/web/static/src/js/search.js	2012-06-07 12:29:23 +0000
@@ -635,6 +635,7 @@
         (new instance.web.search.CustomFilters(this));
         // add Advanced to this.inputs
         (new instance.web.search.Advanced(this));
+        (new instance.web.search.AddToDashboard(this));
 
         // build drawer
         var drawer_started = $.when.apply(
@@ -692,53 +693,6 @@
             select.val('');
         }
     },
-    on_add_to_dashboard: function() {
-        this.$element.find(".oe_search-view-filters-management")[0].selectedIndex = 0;
-        var self = this,
-            menu = instance.webclient.menu,
-            $dialog = $(QWeb.render("SearchView.add_to_dashboard", {
-                dashboards : menu.data.data.children,
-                selected_menu_id : menu.$element.find('a.active').data('menu')
-            }));
-        $dialog.find('input').val(this.fields_view.name);
-        instance.web.dialog($dialog, {
-            modal: true,
-            title: _t("Add to Dashboard"),
-            buttons: [
-                {text: _t("Cancel"), click: function() {
-                    $(this).dialog("close");
-                }},
-                {text: _t("OK"), click: function() {
-                    $(this).dialog("close");
-                    var menu_id = $(this).find("select").val(),
-                        title = $(this).find("input").val(),
-                        data = self.build_search_data(),
-                        context = new instance.web.CompoundContext(),
-                        domain = new instance.web.CompoundDomain();
-                    _.each(data.contexts, function(x) {
-                        context.add(x);
-                    });
-                    _.each(data.domains, function(x) {
-                           domain.add(x);
-                    });
-                    self.rpc('/web/searchview/add_to_dashboard', {
-                        menu_id: menu_id,
-                        action_id: self.getParent().action.id,
-                        context_to_save: context,
-                        domain: domain,
-                        view_mode: self.getParent().active_view,
-                        name: title
-                    }, function(r) {
-                        if (r === false) {
-                            self.do_warn("Could not add filter to dashboard");
-                        } else {
-                            self.do_notify("Filter added to dashboard", '');
-                        }
-                    });
-                }}
-            ]
-        });
-    },
     /**
      * Extract search data from the view's facets.
      *
@@ -1671,6 +1625,54 @@
         }));
     }
 });
+instance.web.search.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();});
+        this.$element.find('.searchview_extended_delete_prop').click(function () {self.$element.toggleClass('oe_opened');});
+        return this.rpc('/web/searchview/get_all_dashboard', {}, function(r) {self.menu_data = r;}).pipe(this.proxy("render_data"))
+    },
+    render_data: function(){
+        var self = this;
+        var selection = instance.web.qweb.render("SearchView.addtodashboard.selection",{selections:this.menu_data});
+        this.$element.find("input").before(selection)
+    },
+    add_dashboard:function(){
+        var self = this,getParent = this.getParent(),view_parent = this.view.getParent();
+        if(!view_parent.action || !this.$element.find("select").val())
+            return this.do_warn("Can't find dashboard action");
+        data = getParent.build_search_data(),
+        context = new instance.web.CompoundContext(getParent.dataset.get_context() || []),
+        domain = new instance.web.CompoundDomain(getParent.dataset.get_domain() || []);
+        this.$element.toggleClass('oe_opened');
+        _.each(data.contexts, function(x) {context.add(x);});
+        _.each(data.domains, function(x) {domain.add(x);});
+        this.rpc('/web/searchview/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.do_notify("Filter added to dashboard", '');
+            }
+        });
+    },
+    show_option:function(){
+        this.$element.toggleClass('oe_opened');
+        if (! this.$element.hasClass('oe_opened'))
+            return;
+        this.$element.find("input").val(this.getParent().fields_view.name || "" );
+    }
+});
 instance.web.search.Advanced = instance.web.search.Input.extend({
     template: 'SearchView.advanced',
     _in_drawer: true,

=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml	2012-06-06 13:20:35 +0000
+++ addons/web/static/src/xml/base.xml	2012-06-07 12:29:23 +0000
@@ -1270,7 +1270,6 @@
     <optgroup label="-- Actions --">
         <option value="advanced_filter">Add Advanced Filter</option>
         <option value="save_filter">Save Filter</option>
-        <option value="add_to_dashboard">Add to Dashboard</option>
         <option value="manage_filters">Manage Filters</option>
     </optgroup>
 </t>
@@ -1281,16 +1280,6 @@
         <p>(Any existing filter with the same name will be replaced)</p>
     </div>
 </t>
-<t t-name="SearchView.add_to_dashboard">
-    <div class="oe_form">
-        <p><b>Select Dashboard to add this filter to:</b></p>
-        <select style="width: 100%; margin-right: 1em;">
-            <option t-foreach="dashboards" t-as="menu" t-att-value="menu.id" t-att-selected="(menu.id == selected_menu_id) || undefined"><t t-esc="menu.name"/></option>
-        </select>
-        <p><b>Title of new Dashboard item:</b></p>
-        <input type="text" style="width: 100%; margin-right: 1em;"/>
-    </div>
-</t>
 <t t-name="SearchView.render_lines">
     <table class="oe-searchview-render-line" border="0" cellspacing="0" cellpadding="0"
            t-foreach="lines" t-as="line">
@@ -1429,6 +1418,25 @@
     <div>
     </div>
 </div>
+<div t-name="SearchView.addtodashboard" class="oe_searchview_dashboard">
+    <h4>Add to Dashboard</h4>
+    <form>
+    <ul>
+        <li>
+         <input placeholder ="Title of new Dashboard item" title = "Title of new Dashboard item" type="text"/>
+         <button class="oe_apply" type="submit">save</button>
+         <a style="width: 30%;" class="searchview_extended_delete_prop button">x</a>
+        </li>
+    </ul>
+    </form>
+</div>
+<t t-name="SearchView.addtodashboard.selection">
+    <select  title = "Select Dashboard to add this filter to">
+        <t t-foreach="selections" t-as="element">
+        <option t-att-value="element.res_id"><t t-esc="element.name"/></option>
+        </t>
+    </select>
+</t>
 <div t-name="SearchView.advanced" class="oe_searchview_advanced">
     <h4>Advanced Search</h4>
     <form>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to