[IMP] change js remove unusfull code and the file name configuration

bzr revid: mva@openerp.com-20120330145149-04gqj8lvleb9pa53
This commit is contained in:
MVA
2012-03-30 16:51:49 +02:00
parent 95a86ec57d
commit d4152e9703
4 changed files with 35 additions and 38 deletions
+22 -17
View File
@@ -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)
+5 -6
View File
@@ -10,7 +10,7 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<group name="default_filters" position="inside">
<field name="context_model_id"/>
<field name="model_id"/>
</group>
</field>
</record>
@@ -21,10 +21,9 @@
<field name="type">form</field>
<field name="arch" type="xml">
<group colspan='4'>
<field name="context_model_id"/>
<field name='context_gdocs_resource_id'/>
<field name='context_name'/>
<field name='context_name_template'/>
<field name="model_id"/>
<field name='gdocs_resource_id'/>
<field name='name_template'/>
</group>
</field>
</record>
@@ -34,7 +33,7 @@
<field name='res_model'>google.docs.config</field>
<field name='type'>ir.actions.act_window</field>
<field name='view_type'>form</field>
<field name='view_id' ref='view_google_docs_config_form'/>
<field name='view_id' ref='view_google_docs_config_tree'/>
</record>
<menuitem name='Google Docs configuration' id='menu_gdocs_config' parent='base.menu_administration'/>
<menuitem name='Models configuration' id='menu_gdocs_model_config' parent='menu_gdocs_config' action='action_google_docs_users_config'/>
+6 -14
View File
@@ -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();
});
},
+2 -1
View File
@@ -5,7 +5,8 @@
<t t-extend="FormView.sidebar.attachments">
<t t-jquery="div.oe-binary-file-set" t-operation="append">
<button class="oe_google_docs_text_button" type="button">
<span>Add A Goole Docs</span>
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
<span>Goole Docs</span>
</button>
</t>
</t>