diff options
| author | Olivier Dony <odo@openerp.com> | 2012-11-07 12:42:02 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2012-11-07 12:42:02 +0100 |
| commit | c9d5148991db5beccedc802ce56efb3689dd1527 (patch) | |
| tree | 3969caa8e049f3df7962c5ebde0ac5bd9dea8130 /addons/google_docs | |
| parent | 657de17a689eb0c71a48f5d2277588ab8278a8ff (diff) | |
| parent | f22e2397d630344ba26875a02181e41b3d297504 (diff) | |
[MERGE] Sync with trunk
bzr revid: odo@openerp.com-20121107114202-mt3gny8e2497m7qf
Diffstat (limited to 'addons/google_docs')
| -rw-r--r-- | addons/google_docs/__openerp__.py | 3 | ||||
| -rw-r--r-- | addons/google_docs/google_docs.py | 28 | ||||
| -rw-r--r-- | addons/google_docs/static/src/js/gdocs.js | 57 | ||||
| -rw-r--r-- | addons/google_docs/static/src/xml/gdocs.xml | 8 |
4 files changed, 56 insertions, 40 deletions
diff --git a/addons/google_docs/__openerp__.py b/addons/google_docs/__openerp__.py index 8b9a4123aa9..2d064fdb8a9 100644 --- a/addons/google_docs/__openerp__.py +++ b/addons/google_docs/__openerp__.py @@ -28,11 +28,12 @@ 'installable': True, 'auto_install': False, 'js': ['static/src/js/gdocs.js'], + 'qweb': ['static/src/xml/gdocs.xml'], 'data': [ 'security/ir.model.access.csv', 'res_config_user_view.xml' ], - 'depends': ['google_base_account'], + 'depends': ['google_base_account','document'], 'description': """ Module to attach a google document to any model. ================================================ diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 5ff80530c94..462c8240810 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -17,7 +17,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## - +from datetime import datetime +from tools import DEFAULT_SERVER_DATETIME_FORMAT from osv import osv, fields from tools.translate import _ try: @@ -61,7 +62,8 @@ class google_docs_ir_attachment(osv.osv): #login with the base account google module client = self._auth(cr, uid, context=context) # create the document in google docs - local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) + title = "%s %s" % (context.get("name","Untitled Document."), datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT)) + local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL,title=title) #create a new doc in Google Docs gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') # create an ir.attachment into the db @@ -69,10 +71,12 @@ class google_docs_ir_attachment(osv.osv): 'res_model': res_model, 'res_id': res_id, 'type': 'url', - 'name': _('Google Doc'), + 'name': title, 'url': gdocs_resource.get_alternate_link().href, }, context=context) - return gdocs_resource.resource_id.text + return {'resource_id': gdocs_resource.resource_id.text, + 'title': title, + 'url': gdocs_resource.get_alternate_link().href} def copy_gdoc(self, cr, uid, res_model, res_id, name_gdocs, gdoc_template_id, context=None): ''' @@ -89,7 +93,7 @@ class google_docs_ir_attachment(osv.osv): try: original_resource = client.get_resource_by_id(gdoc_template_id) #copy the document you choose in the configuration - copy_resource = client.copy_resource(original_resource, 'copy_%s' % original_resource.title.text) + copy_resource = client.copy_resource(original_resource, name_gdocs) except: raise osv.except_osv(_('Google Docs Error!'), _("Your resource id is not correct. You can find the id in the google docs URL.")) # create an ir.attachment @@ -114,7 +118,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 +130,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,15 +146,15 @@ 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` *for a presentation (slide show) document with url like `https://docs.google.com/a/openerp.com/presentation/d/123456789/edit#slide=id.p`, the ID is `presentation:123456789` *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'), +''', required=True), + 'name_template': fields.char('Google Doc Name Pattern', size=64, help='Choose how the new google docs will be named, on google side. Eg. gdoc_%(field_name)s', 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..0cc93b2510c 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().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(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> |
