diff options
| author | Tejas Tank <tta@openerp.com> | 2012-10-23 16:11:08 +0530 |
|---|---|---|
| committer | Tejas Tank <tta@openerp.com> | 2012-10-23 16:11:08 +0530 |
| commit | d62958e5abf517ee87c4b496c35ec66e280d5fcd (patch) | |
| tree | 2ae709f173e04e898983699998a69c344c0bb57a /addons/google_docs | |
| parent | c55438e695d03854ebf1b82aa0d6b33b3dc278f0 (diff) | |
| parent | 0841cc1331ffd46f39cd9407ed852cc35ebad7cd (diff) | |
Google Doc Integration.
bzr revid: tta@openerp.com-20121023104108-rxjfb37ydv2108b8
Diffstat (limited to 'addons/google_docs')
| -rw-r--r-- | addons/google_docs/google_docs.py | 12 | ||||
| -rw-r--r-- | addons/google_docs/static/src/js/gdocs.js | 56 | ||||
| -rw-r--r-- | addons/google_docs/static/src/xml/gdocs.xml | 8 |
3 files changed, 43 insertions, 33 deletions
diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 5ff80530c94..f0f6f22a7c5 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -114,7 +114,8 @@ class google_docs_ir_attachment(osv.osv): a length of 1 element only (batch processing is not supported in the code, though nothing really prevent it) :return: the google document object created ''' - assert len(ids) == 1, 'Creating google docs may only be done by one at a time' + if len(ids) != 1: + raise osv.except_osv(_('Google Docs Error!'), _("Creating google docs may only be done by one at a time.")) res_id = ids[0] pool_ir_attachment = self.pool.get('ir.attachment') pool_gdoc_config = self.pool.get('google.docs.config') @@ -125,7 +126,10 @@ class google_docs_ir_attachment(osv.osv): google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', res_model)], context=context) if google_docs_config: name_gdocs = pool_gdoc_config.browse(cr, uid, google_docs_config, context=context)[0].name_template - name_gdocs = name_gdocs % model_fields_dic + try: + name_gdocs = name_gdocs % model_fields_dic + except: + raise osv.except_osv(_('Key Error!'), _("Your Google Doc Name Pattern's key does not found in object.")) google_template_id = pool_gdoc_config.browse(cr, uid, google_docs_config[0], context=context).gdocs_resource_id google_document = pool_ir_attachment.copy_gdoc(cr, uid, res_model, res_id, name_gdocs, google_template_id, context=context) else: @@ -138,7 +142,7 @@ class config(osv.osv): _columns = { 'model_id': fields.many2one('ir.model', 'Model', required=True), - 'gdocs_resource_id': fields.char('Google Resource ID to Use as Template', size=64,help=''' + 'gdocs_resource_id': fields.char('Google Resource ID to Use as Template', size=64, help=''' This is the id of the template document, on google side. You can find it thanks to its URL: *for a text document with url like `https://docs.google.com/a/openerp.com/document/d/123456789/edit`, the ID is `document:123456789` *for a spreadsheet document with url like `https://docs.google.com/a/openerp.com/spreadsheet/ccc?key=123456789#gid=0`, the ID is `spreadsheet:123456789` @@ -146,7 +150,7 @@ This is the id of the template document, on google side. You can find it thanks *for a drawing document with url like `https://docs.google.com/a/openerp.com/drawings/d/123456789/edit`, the ID is `drawings:123456789` ... '''), - 'name_template': fields.char('Google Doc Name Pattern', size=64, help='Choose how the new google docs will be named, on google side'), + 'name_template': fields.char('Google Doc Name Pattern', size=64, help='Choose how the new google docs will be named, on google side', required=True), } _defaults = { diff --git a/addons/google_docs/static/src/js/gdocs.js b/addons/google_docs/static/src/js/gdocs.js index 2aafdd3de4b..6e8ff59f377 100644 --- a/addons/google_docs/static/src/js/gdocs.js +++ b/addons/google_docs/static/src/js/gdocs.js @@ -1,41 +1,39 @@ 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().then(function (context) { - var ds = new instance.web.DataSet(this, 'ir.attachment', context); - ds.call('google_doc_get', [form.dataset.model, [form.datarecord.id], context]).then(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().then(function (context) { + var ds = new instance.web.DataSet(this, 'ir.attachment', context); + ds.call('google_doc_get', [view.dataset.model, ids, context]).then(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(){ + 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> |
