diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 6e91ee64658..3045cbab279 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -47,7 +47,7 @@ class google_docs_ir_attachment(osv.osv): raise osv.except_osv(('Google Docs Error!'),("Check your google configuration in users/synchronization") ) return client - def create_empty_google_doc(self, cr, uid, model, ids, type_doc,context=None): + def create_empty_google_doc(self, cr, uid, name_gdocs, model, ids, type_doc,context=None): '''Associate a copy of the gdoc identified by 'gdocs_res_id' to the current entity. @param cr: the current row from the database cursor. @param uid: the current user ID, for security checks. @@ -62,24 +62,22 @@ class google_docs_ir_attachment(osv.osv): local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) #create a new doc in Google Docs gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') - # register into the db self.create(cr, uid, { 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': ('new_%s' % gdocs_resource.title.text), + 'name': 'Google Doc', 'url': gdocs_resource.get_alternate_link().href, },context=context) return 1 - def copy_gdoc(self, cr, uid, model, google_res_id, ids,context=None): + def copy_gdoc(self, cr, uid, name_gdocs, model, google_res_id, ids,context=None): ''' copy an existing document in google docs ''' - client = self._auth(cr, uid) # fetch and copy the original document try: @@ -93,7 +91,7 @@ class google_docs_ir_attachment(osv.osv): 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'copy_%s' % original_resource.title.text, + 'name': name_gdocs, 'url': copy_resource.get_alternate_link().href },context=context) @@ -104,14 +102,20 @@ class google_docs(osv.osv): def doc_get(self, cr, uid, model, id, type_doc,context=None): ir_attachment_ref = self.pool.get('ir.attachment') - google_docs_config = self.pool.get('google.docs.config').search(cr, uid, [('context_model_id', '=', model)]) + pool_gdoc_config = self.pool.get('google.docs.config') + google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', model)]) + name_gdocs='' + if google_docs_config: + name_gdocs = pool_gdoc_config.browse(cr,uid,google_docs_config,context=context)[0].name_template + print name_gdocs + # check if a model is configurate with a template if google_docs_config: for google_config in self.pool.get('google.docs.config').browse(cr,uid,google_docs_config,context=context): - google_res_id = google_config.context_gdocs_resource_id - google_document = ir_attachment_ref.copy_gdoc(cr, uid, model,google_res_id, id) + google_res_id = google_config.gdocs_resource_id + google_document = ir_attachment_ref.copy_gdoc(cr, uid,name_gdocs ,model,google_res_id, id) else: - google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc) + google_document = ir_attachment_ref.create_empty_google_doc(cr, uid,name_gdocs, model, id, type_doc) return -1 @@ -120,24 +124,25 @@ class config(osv.osv): _description = "Google Docs templates config" _columns = { - 'context_model_id': fields.many2one('ir.model', 'Model'), - 'context_gdocs_resource_id': fields.char('Google resource ID', size=64,help='This is the id of the template document you kind find it in the URL'), - 'context_name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), - 'context_name': fields.char('Name', size=64, help='This is the attachment\'s name. As well, it appears on the panel.'), + 'model_id': fields.many2one('ir.model', 'Model'), + 'gdocs_resource_id': fields.char('Google resource ID', size=64,help='This is the id of the template document you kind find it in the URL'), + 'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), } _defaults = { - 'context_name_template': 'Google Document', - 'context_name': 'pr_%(name)', + 'name_template': 'pr_%(name)', } def get_config(self, cr, uid, model): ''' Method use with the js to hidde or show the add google doc button @return : list of configuration ids or false ''' - domain = [('context_model_id', '=', model)] + domain = [('model_id', '=', model)] if self.search_count(cr, uid, domain) != 0: return False + # attached only one document to a model + if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%')]) !=0: + return False else: return self.search(cr, uid, domain) diff --git a/addons/google_docs/res_config_user_view.xml b/addons/google_docs/res_config_user_view.xml index be56f324d2d..46abe5b2d80 100644 --- a/addons/google_docs/res_config_user_view.xml +++ b/addons/google_docs/res_config_user_view.xml @@ -10,7 +10,7 @@ tree - + @@ -21,10 +21,9 @@ form - - - - + + + @@ -34,7 +33,7 @@ google.docs.config ir.actions.act_window form - + diff --git a/addons/google_docs/static/src/js/gdocs.js b/addons/google_docs/static/src/js/gdocs.js index c32dc4c8829..9dc4f5c88d3 100644 --- a/addons/google_docs/static/src/js/gdocs.js +++ b/addons/google_docs/static/src/js/gdocs.js @@ -8,36 +8,28 @@ openerp.google_docs = function(instance, session) { var self = this; var config = new instance.web.DataSet(this, 'google.docs.config', this.view.dataset.get_context()); config.call('get_config', [this.view.dataset.ids[this.view.dataset.index]], function(r) { - console.log(r); // if the configuration isn't set, the buttons should be hidden. if (r==false) { - $('.oe_google_docs_text_button').css('display', 'none'); + $('.oe_google_docs_text_button',this.$element).hide(); return; } var attachment = new instance.web.DataSet(this, 'ir.attachment', self.view.dataset.get_context()); attachment.call('copy_gdoc', [self.view.dataset.model, [self.view.datarecord.id]], function(res) { - console.log(res); }); }); }, + start: function() { + this._super(); + console.log($('.oe_google_docs_text_button',this.$element)) + $('.oe_google_docs_text_button',this.$element) + }, on_add_text_gdoc: function() { var self = this; var $gdocbtn = this.$element.find('.oe_google_docs_text_button'); $gdocbtn.attr('disabled', 'true').find('img, span').toggle(); var ds = new instance.web.DataSet(this, 'google.docs', this.view.dataset.get_context()); ds.call('doc_get', [this.view.dataset.model, [this.view.datarecord.id], 'text'], function(r) { - console.log(r); - if (r == 'False') { - var params = { - error: response, - message: "The user google credentials are not set yet. Contact your administrator for help." - } - $(openerp.web.qweb.render("DialogWarning", params)).dialog({ - title: "User Google credentials are not yet set.", - modal: true, - }); - } self.do_update(); }); }, diff --git a/addons/google_docs/static/src/xml/gdocs.xml b/addons/google_docs/static/src/xml/gdocs.xml index acb352bf9b0..2de7efcbd43 100644 --- a/addons/google_docs/static/src/xml/gdocs.xml +++ b/addons/google_docs/static/src/xml/gdocs.xml @@ -5,7 +5,8 @@