2013-06-26 09:30:19 +00:00
|
|
|
openerp.google_drive = function (instance, m) {
|
2013-05-09 14:10:01 +00:00
|
|
|
var _t = instance.web._t,
|
|
|
|
QWeb = instance.web.qweb;
|
2013-05-17 10:19:31 +00:00
|
|
|
|
2012-10-17 07:10:08 +00:00
|
|
|
instance.web.Sidebar.include({
|
2013-05-09 14:10:01 +00:00
|
|
|
start: function () {
|
2012-08-30 16:15:31 +00:00
|
|
|
var self = this;
|
2013-05-09 14:10:01 +00:00
|
|
|
var ids
|
2012-10-17 06:49:06 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-10-19 10:40:20 +00:00
|
|
|
var view = self.getParent();
|
2013-03-08 13:30:39 +00:00
|
|
|
var result;
|
2013-05-09 14:10:01 +00:00
|
|
|
if (view.fields_view.type == "form") {
|
|
|
|
ids = []
|
|
|
|
view.on("load_record", self, function (r) {
|
|
|
|
ids = [r.id]
|
|
|
|
self.add_gdoc_items(view, r.id)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
add_gdoc_items: function (view, res_id) {
|
|
|
|
var self = this;
|
|
|
|
var gdoc_item = _.indexOf(_.pluck(self.items.other, 'classname'), 'oe_share_gdoc');
|
|
|
|
if (gdoc_item !== -1) {
|
|
|
|
self.items.other.splice(gdoc_item, 1);
|
|
|
|
}
|
|
|
|
if (res_id) {
|
|
|
|
view.sidebar_eval_context().done(function (context) {
|
2013-06-26 09:30:19 +00:00
|
|
|
var ds = new instance.web.DataSet(this, 'google.drive.config', context);
|
|
|
|
ds.call('get_google_drive_config', [view.dataset.model, res_id, context]).done(function (r) {
|
2013-05-09 14:10:01 +00:00
|
|
|
if (!_.isEmpty(r)) {
|
|
|
|
_.each(r, function (res) {
|
|
|
|
var g_item = _.indexOf(_.pluck(self.items.other, 'label'), res.name);
|
|
|
|
if (g_item !== -1) {
|
|
|
|
self.items.other.splice(g_item, 1);
|
|
|
|
}
|
|
|
|
self.add_items('other', [{
|
2013-06-26 09:30:19 +00:00
|
|
|
label: res.name+ '<img style="position:absolute;right:5px;height:20px;width:20px;" title="Google Drive" src="google_drive/static/src/img/drive_icon.png"/>',
|
2013-05-09 14:10:01 +00:00
|
|
|
config_id: res.id,
|
|
|
|
res_id: res_id,
|
|
|
|
res_model: view.dataset.model,
|
|
|
|
callback: self.on_google_doc,
|
|
|
|
classname: 'oe_share_gdoc'
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2013-05-17 10:19:31 +00:00
|
|
|
|
2013-05-10 06:35:01 +00:00
|
|
|
fetch: function (model, fields, domain, ctx) {
|
2013-05-09 14:10:01 +00:00
|
|
|
return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all()
|
|
|
|
},
|
2013-05-17 10:19:31 +00:00
|
|
|
|
2013-05-09 14:10:01 +00:00
|
|
|
on_google_doc: function (doc_item) {
|
2013-05-10 06:35:01 +00:00
|
|
|
var self = this;
|
|
|
|
self.config = doc_item;
|
2013-06-26 09:30:19 +00:00
|
|
|
var loaded = self.fetch('google.drive.config', ['google_drive_resource_id', 'google_drive_client_id'], [['id', '=', doc_item.config_id]])
|
2013-05-10 06:35:01 +00:00
|
|
|
.then(function (configs) {
|
2013-06-26 09:30:19 +00:00
|
|
|
var ds = new instance.web.DataSet(self, 'google.drive.config');
|
|
|
|
ds.call('get_google_doc_name', [[doc_item.config_id], doc_item.res_id,configs[0].google_drive_resource_id]).done(function (r) {
|
2013-05-09 14:10:01 +00:00
|
|
|
if (!_.isEmpty(r)) {
|
2013-05-23 10:41:55 +00:00
|
|
|
_.each(r, function (res) {
|
|
|
|
if(res.url)
|
|
|
|
{
|
|
|
|
window.open(res.url, '_blank');
|
|
|
|
}
|
|
|
|
});
|
2013-05-09 14:10:01 +00:00
|
|
|
}
|
2013-05-10 06:35:01 +00:00
|
|
|
});
|
2013-05-09 14:10:01 +00:00
|
|
|
});
|
|
|
|
},
|
2013-05-17 10:19:31 +00:00
|
|
|
|
2012-10-03 11:22:27 +00:00
|
|
|
});
|
2013-05-09 14:10:01 +00:00
|
|
|
};
|