summaryrefslogtreecommitdiff
path: root/addons/pad/static
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2011-10-13 19:03:27 +0200
committerOlivier Dony <odo@openerp.com>2011-10-13 19:03:27 +0200
commit3bffe65b2ca8bc50ece644e7947ad2bbd5c9341a (patch)
treeb307874680dbdce7b2f5109b7b696ea38e679e20 /addons/pad/static
parenta93ca01b5b1365f92e191e3c429ef655e751b455 (diff)
parent8a7c61cb96a541a9aaca51ffe3ee903407b26360 (diff)
[MERGE] sync with latest trunk
bzr revid: odo@openerp.com-20111013170327-9rvfdkbgj01hdgxb
Diffstat (limited to 'addons/pad/static')
-rw-r--r--addons/pad/static/src/js/pad.js71
-rw-r--r--addons/pad/static/src/xml/pad.xml13
2 files changed, 84 insertions, 0 deletions
diff --git a/addons/pad/static/src/js/pad.js b/addons/pad/static/src/js/pad.js
new file mode 100644
index 00000000000..c6b977b0f78
--- /dev/null
+++ b/addons/pad/static/src/js/pad.js
@@ -0,0 +1,71 @@
+
+openerp.pad = function(instance) {
+
+var QWeb = instance.web.qweb;
+QWeb.add_template('/pad/static/src/xml/pad.xml');
+
+instance.web.form.SidebarAttachments = instance.web.form.SidebarAttachments.extend({
+
+ pad_prefix: undefined,
+
+ on_add_pad: function() {
+ var self = this;
+ var $padbtn = this.$element.find('button.pad');
+ $padbtn.attr('disabled', 'true').find('img, span').toggle();
+
+ this.do_load_pad_prefix(function() {
+ var attachment = new instance.web.DataSet(self, 'ir.attachment', self.view.dataset.get_context());
+ var r = (((1+Math.random())*0x10000)|0).toString(16).substring(1);
+ attachment.create({
+ res_model: self.view.dataset.model,
+ res_id: self.view.datarecord.id,
+ type: 'url',
+ name: 'Pad',
+ url: self.pad_prefix + r,
+ }, function() {
+ self.do_update();
+ });
+ });
+
+ },
+
+ do_load_pad_prefix: function(continuation) {
+ var self = this;
+ if (this.pad_prefix === undefined) {
+ var user = new instance.web.DataSet(this, 'res.users', this.view.dataset.get_context());
+ var company = new instance.web.DataSet(this, 'res.company', this.view.dataset.get_context());
+ user.read_ids([this.session.uid], ['company_id'], function(result) {
+ company.read_ids([result[0].company_id[0]], ['pad_index'], function(result) {
+ var pad_index = _(result[0].pad_index).strip().replace(/\/$/, "");;
+ if (pad_index) {
+ self.pad_prefix = _('%s/%s-%s-%d-').sprintf(pad_index, self.session.db, self.view.dataset.model, self.view.datarecord.id);
+ } else {
+ self.pad_prefix = null;
+ }
+ continuation();
+ });
+ });
+ } else {
+ continuation();
+ }
+ },
+
+ on_attachments_loaded: function(attachments) {
+ this._super(attachments);
+ var self = this;
+ this.do_load_pad_prefix(function() {
+ var $padbtn = self.$element.find('button.pad');
+ var is_pad = function(a) {
+ return a.type == 'url' && _(a.url).startsWith(self.pad_prefix);
+ };
+ if (!self.pad_prefix || _.any(attachments, is_pad)) {
+ $padbtn.hide();
+ } else {
+ $padbtn.show().click(self.on_add_pad);
+ }
+ });
+
+ },
+});
+
+};
diff --git a/addons/pad/static/src/xml/pad.xml b/addons/pad/static/src/xml/pad.xml
new file mode 100644
index 00000000000..c17464e6646
--- /dev/null
+++ b/addons/pad/static/src/xml/pad.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vim:fdl=1:
+-->
+<templates id="template" xml:space="preserve">
+ <t t-extend="FormView.sidebar.attachments">
+ <t t-jquery="div.oe-binary-file-set" t-operation="append">
+ <button class="button pad" type="button">
+ <img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
+ <span>Add Pad</span>
+ </button>
+ </t>
+ </t>
+</templates>