From f26fea2a09ab5841a22c0413e6d51c932cf9cac3 Mon Sep 17 00:00:00 2001 From: "Dharti Ratani (Open ERP)" Date: Fri, 8 Mar 2013 19:00:39 +0530 Subject: [IMP]Adding virtual entry of gdoc template for a particular record to more based on filter bzr revid: dhr@tinyerp.com-20130308133039-lme2p04ak2pviurt --- addons/google_docs/static/src/js/gdocs.js | 86 +++++++++++++++++++---------- addons/google_docs/static/src/xml/gdocs.xml | 8 ++- 2 files changed, 61 insertions(+), 33 deletions(-) (limited to 'addons/google_docs/static/src') diff --git a/addons/google_docs/static/src/js/gdocs.js b/addons/google_docs/static/src/js/gdocs.js index 1cc511ef4d9..a0f1cba3b9b 100644 --- a/addons/google_docs/static/src/js/gdocs.js +++ b/addons/google_docs/static/src/js/gdocs.js @@ -3,38 +3,64 @@ var _t = instance.web._t, QWeb = instance.web.qweb; instance.web.Sidebar.include({ - redraw: function() { + + start: function() { var self = this; + var ids this._super.apply(this, arguments); - self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddGoogleDocumentItem', {widget: self})) - self.$el.find('.oe_sidebar_add_google_doc').on('click', function (e) { - self.on_google_doc(); - }); - }, - on_google_doc: function() { - var self = this; var view = self.getParent(); - var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; - if( !_.isEmpty(ids) ){ - view.sidebar_eval_context().done(function (context) { - var ds = new instance.web.DataSet(this, 'ir.attachment', context); - ds.call('google_doc_get', [view.dataset.model, ids, context]).done(function(r) { - if (r == 'False') { - var params = { - error: response, - message: _t("The user google credentials are not set yet. Contact your administrator for help.") - } - $(openerp.web.qweb.render("DialogWarning", params)).dialog({ - title: _t("User Google credentials are not yet set."), - modal: true, - }); - } - }).done(function(r){ - window.open(r.url,"_blank"); - view.reload(); - }); - }); - } - } + var result; + if(view.fields_view.type == "form"){ + ids = [] + view.on("load_record", self, function(r){ + ids = [r.id] + self.add_gdoc_items(view,ids) + }); + } + }, + + add_gdoc_items: function(view,ids){ + $('.oe_share_gdoc').remove(); + var self = this; + if( !_.isEmpty(ids) ){ + view.sidebar_eval_context().done(function (context) { + var ds = new instance.web.DataSet(this, 'ir.attachment', context); + ds.call('google_doc_get', [view.dataset.model, ids, context]).done(function(r) { + console.log("thjoid ",self.items['other']) + if(!_.isEmpty(r)){ + _.each(r,function(res){ + _.each(self.items['other'],function(others){ + if(others['label'] == res){ + self.items['other'].pop() + } + }) + self.add_items('other', [ + { label: res, + callback: self.on_google_doc, + classname: 'oe_share_gdoc' }, + ]); + }) + } + }); + }); + } + }, + + on_google_doc: function(r) { + var self = this; + var view = self.getParent(); + var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; + if( !_.isEmpty(ids) ){ + view.sidebar_eval_context().done(function (context) { + var ds = new instance.web.DataSet(this, 'ir.attachment', context); + ds.call('get_attachment', [view.dataset.model, r, ids, context]).done(function(res) { + console.log('resssssss',res) + window.open(res.url,"_blank"); + view.reload(); + }) + + }); + } + } }); }; diff --git a/addons/google_docs/static/src/xml/gdocs.xml b/addons/google_docs/static/src/xml/gdocs.xml index e0cfd5cf25c..a90f4034ea8 100644 --- a/addons/google_docs/static/src/xml/gdocs.xml +++ b/addons/google_docs/static/src/xml/gdocs.xml @@ -1,8 +1,10 @@ - + \ No newline at end of file -- cgit v1.2.3