diff options
| author | Fabien Meghazi <fme@openerp.com> | 2012-11-05 09:48:38 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2012-11-05 09:48:38 +0100 |
| commit | 22ad7a70f783a799b65e73c0342db7b2627a0851 (patch) | |
| tree | 7a4b9e9b4b11d7c778e2ec06cf5c45dd2593b0fa /addons/google_docs/static/src | |
| parent | a2715888c16f519d531a5aa77f0034791e330758 (diff) | |
| parent | 29fffbc97d8970513114b7b76763f002aa73e395 (diff) | |
[MERGE] trunk
bzr revid: fme@openerp.com-20121105084838-gwc7xb19f7131vbi
Diffstat (limited to 'addons/google_docs/static/src')
| -rw-r--r-- | addons/google_docs/static/src/js/gdocs.js | 57 | ||||
| -rw-r--r-- | addons/google_docs/static/src/xml/gdocs.xml | 8 |
2 files changed, 36 insertions, 29 deletions
diff --git a/addons/google_docs/static/src/js/gdocs.js b/addons/google_docs/static/src/js/gdocs.js index 6e3f30a2c1f..45e1d09d42c 100644 --- a/addons/google_docs/static/src/js/gdocs.js +++ b/addons/google_docs/static/src/js/gdocs.js @@ -1,41 +1,40 @@ openerp.google_docs = function(instance, m) { -var _t = instance.web._t; +var _t = instance.web._t, + QWeb = instance.web.qweb; - instance.web.Sidebar = instance.web.Sidebar.extend({ - on_attachments_loaded: function(attachments) { + instance.web.Sidebar.include({ + redraw: function() { var self = this; - self._super(attachments); - // if attachment contains a google doc url do nothing - // else display a button to create a google doc - var flag = false; - _.each(attachments, function(i) { - if (i.url && i.url.match('/docs.google.com/')) { flag = true; } + 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(); }); - if (! flag) { - this.add_items('files', [ - { label: _t('Add Google Doc...'), callback: self.on_google_doc }, - ]); - } }, on_google_doc: function() { var self = this; - var form = self.getParent(); - form.sidebar_context().done(function (context) { - var ds = new instance.web.DataSet(this, 'ir.attachment', context); - ds.call('google_doc_get', [form.dataset.model, [form.datarecord.id], 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.") + var view = self.getParent(); + var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; + if( !_.isEmpty(ids) ){ + view.sidebar_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, + }); } - $(openerp.web.qweb.render("DialogWarning", params)).dialog({ - title: _t("User Google credentials are not yet set."), - modal: true, - }); - } - form.reload(); + }).done(function(r){ + window.open(r.url,"_blank"); + view.reload(); + }); }); - }); + } } }); }; diff --git a/addons/google_docs/static/src/xml/gdocs.xml b/addons/google_docs/static/src/xml/gdocs.xml new file mode 100644 index 00000000000..0c8d9c3b01f --- /dev/null +++ b/addons/google_docs/static/src/xml/gdocs.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- vim:fdl=1: +--> +<templates id="template" xml:space="preserve"> +<t t-name="AddGoogleDocumentItem"> + <li class="oe_sidebar_add_google_doc"><span><b>Add Google Doc...</b></span></li> +</t> +</templates> |
