[IMP] imporve code + usability

bzr revid: rgaopenerp-20121012135342-hjj8slov7yvfwal0
This commit is contained in:
RGA(OpenERP)
2012-10-12 19:23:42 +05:30
parent f830a534d6
commit 0b508d66fe
3 changed files with 22 additions and 17 deletions
+1
View File
@@ -28,6 +28,7 @@
'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'
+13 -17
View File
@@ -1,28 +1,22 @@
openerp.google_docs = function(instance, m) {
var _t = instance.web._t;
var QWeb = instance.web.qweb,
_t = instance.web._t;
instance.web.Sidebar = instance.web.Sidebar.extend({
on_attachments_loaded: function(attachments) {
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; }
redraw: function() {
var self = this;
this._super.apply(this, arguments);
self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('Google_doc', {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], function(r) {
def = ds.call('google_doc_get', [form.dataset.model, [form.datarecord.id], context], function(r) {
if (r == 'False') {
var params = {
error: response,
@@ -33,8 +27,10 @@ var _t = instance.web._t;
modal: true,
});
}
form.reload();
});
}).done(function(){
form.reload();
});
})
}
})
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="Google_doc">
<li class="oe_sidebar_add_google_doc"><span><b>Add Google Doc...</b></span></li>
</t>
</templates>