summaryrefslogtreecommitdiff
path: root/addons/google_docs/static/src
diff options
context:
space:
mode:
authorParth Gajjar (Open ERP) <pga@tinyerp.com>2013-05-23 16:11:55 +0530
committerParth Gajjar (Open ERP) <pga@tinyerp.com>2013-05-23 16:11:55 +0530
commit5b9b00631de5020bd5560fe788eab7a703815253 (patch)
treecac50d90ac27044f96ab33ce87f6dedc13d6e2d2 /addons/google_docs/static/src
parentb4e6c2109c715c66e14e6f99446fda6da7e5b433 (diff)
[ADD] Added OAuth integration through python, Added Documentation
bzr revid: pga@tinyerp.com-20130523104155-83gmp2gucvackppv
Diffstat (limited to 'addons/google_docs/static/src')
-rw-r--r--addons/google_docs/static/src/img/drive_icon.pngbin0 -> 2148 bytes
-rw-r--r--addons/google_docs/static/src/img/drive_icon_mono.pngbin0 -> 479 bytes
-rw-r--r--addons/google_docs/static/src/js/gdocs.js123
3 files changed, 8 insertions, 115 deletions
diff --git a/addons/google_docs/static/src/img/drive_icon.png b/addons/google_docs/static/src/img/drive_icon.png
new file mode 100644
index 00000000000..590dde867f4
--- /dev/null
+++ b/addons/google_docs/static/src/img/drive_icon.png
Binary files differ
diff --git a/addons/google_docs/static/src/img/drive_icon_mono.png b/addons/google_docs/static/src/img/drive_icon_mono.png
new file mode 100644
index 00000000000..9fd836b6988
--- /dev/null
+++ b/addons/google_docs/static/src/img/drive_icon_mono.png
Binary files differ
diff --git a/addons/google_docs/static/src/js/gdocs.js b/addons/google_docs/static/src/js/gdocs.js
index 0e0a633ab1c..505815f4b2e 100644
--- a/addons/google_docs/static/src/js/gdocs.js
+++ b/addons/google_docs/static/src/js/gdocs.js
@@ -9,7 +9,6 @@ openerp.google_docs = function (instance, m) {
this._super.apply(this, arguments);
var view = self.getParent();
var result;
- this.check_url();
if (view.fields_view.type == "form") {
ids = []
view.on("load_record", self, function (r) {
@@ -18,36 +17,6 @@ openerp.google_docs = function (instance, m) {
});
}
},
- check_url: function () {
- /* This function check URL and if there is 'state' object (dictionary) sent by google,
- * it will fetch file 'exportIds' from 'state' object and redirect to corresponding record in openerp
- */
- self = this;
- var state = this.getUrlVars();
- if (state) {
- file_obj = JSON.parse(state);
- var loaded = self.fetch('ir.attachment', ['res_model', 'res_id', 'url', 'name'], [['url', 'ilike', '%' + file_obj.exportIds[0] + '%']])
- .then(function (att) {
- console.log(att);
- if (att.length != 0) {
- url = window.location.href.replace(/(\&)(.*)/, "");
- url = url + "#id=" + att[0].res_id + "&model=" + att[0].res_model;
- $('body').hide();
- window.open(url, '_self');
- }
- });
- }
- },
- getUrlVars: function () {
- var parts=unescape(window.location.href);
- var n=parts.match(/(state=)(.*})/);
- if(n && n.length>2){
- return n[2];
- }
- else{
- return false
- }
- },
add_gdoc_items: function (view, res_id) {
var self = this;
var gdoc_item = _.indexOf(_.pluck(self.items.other, 'classname'), 'oe_share_gdoc');
@@ -65,7 +34,7 @@ openerp.google_docs = function (instance, m) {
self.items.other.splice(g_item, 1);
}
self.add_items('other', [{
- label: res.name,
+ label: res.name+ '<img style="height:20px;width:20px;float:right;" src="google_docs/static/src/img/drive_icon.png"/>',
config_id: res.id,
res_id: res_id,
res_model: view.dataset.model,
@@ -90,94 +59,18 @@ openerp.google_docs = function (instance, m) {
var loaded = self.fetch('google.docs.config', ['gdocs_resource_id', 'google_client_id'], [['id', '=', doc_item.config_id]])
.then(function (configs) {
var ds = new instance.web.DataSet(self, 'google.docs.config');
- ds.call('get_google_doc_name', [[doc_item.config_id], doc_item.res_id]).done(function (r) {
+ ds.call('get_google_doc_name', [[doc_item.config_id], doc_item.res_id,configs[0].gdocs_resource_id]).done(function (r) {
if (!_.isEmpty(r)) {
- self.OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
- self.VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
- self.SCOPES = 'https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.install';
- self.CLIENT_ID = configs[0].google_client_id;
- self.GDOC_NAME = r[doc_item.config_id]['name'];
- self.GDOCS_TEMPLATE_ID = configs[0].gdocs_resource_id;
- self.GDOC_URL = r[doc_item.config_id]['url'];
- self.handleClientLoad();
+ _.each(r, function (res) {
+ if(res.url)
+ {
+ window.open(res.url, '_blank');
+ }
+ });
}
});
});
},
- handleClientLoad: function () {
- var self = this;
- window.setTimeout(function () {
- self.checkAuth(self)
- }, 1);
- },
-
- checkAuth: function (self) {
- gapi.auth.authorize({
- 'client_id': self.CLIENT_ID,
- 'scope': self.SCOPES,
- 'immediate': true
- }, function (authResult) {
- self.handleAuthResult(self, authResult)
- });
- },
-
- handleAuthResult: function (self, authResult) {
-
- if (authResult && !authResult.error) {
- self.clientLoad(self);
- } else {
- gapi.auth.authorize({
- 'client_id': self.CLIENT_ID,
- 'scope': self.SCOPES,
- 'immediate': false
- }, function (authResult) {
- self.handleAuthResult(self, authResult)
- });
- }
- },
-
- clientLoad: function (self) {
- gapi.client.load('drive', 'v2', function () {
- if (self.GDOC_URL == false) {
- self.copyFile(self.config, self.GDOCS_TEMPLATE_ID, self.GDOC_NAME);
- } else {
- window.open(self.GDOC_URL, '_blank');
- }
- });
- },
-
- copyFile: function (config, originFileId, copyTitle) {
- discription = window.location.href;
- discription = discription.replace(/(\&)?menu_id(.*)/, "");
- discription = discription.replace(/(\&)?action(.*)/, "");
- var body = {
- 'title': copyTitle,
- "description": 'Click Below link for open record in OpenERP\n' + discription,
- };
- var request = gapi.client.drive.files.copy({
- 'fileId': originFileId,
- 'resource': body
- });
- request.execute(function (resp) {
- console.log('Copy ID: ' + resp.id);
- var get_new_file = gapi.client.drive.files.get({
- 'fileId': resp.id
- });
- get_new_file.execute(function (file) {
- var ds = new instance.web.DataSet(self, 'ir.attachment');
- vals = {
- 'res_model': config.res_model,
- 'res_id': config.res_id,
- 'type': 'url',
- 'name': copyTitle,
- 'url': file.alternateLink
- }
- ds.call('create', [vals]).done(function (r) {
- window.open(file.alternateLink, '_blank');
- });
- });
- });
- },
});
}; \ No newline at end of file