diff options
| author | Tejas Tank <tta@openerp.com> | 2012-04-27 14:21:03 +0530 |
|---|---|---|
| committer | Tejas Tank <tta@openerp.com> | 2012-04-27 14:21:03 +0530 |
| commit | ae848b7fd9628a0385fd2b1f6bb5d62c8bd2f864 (patch) | |
| tree | bd04f21be7f64f2945961fbaba2cd4c8b13924a1 /addons/pad/static | |
| parent | 7de8c025023aa063b204d0b7679e0925ec133405 (diff) | |
| parent | 8d240b5775da32dc41bb0d9b5fc7255d1b49ea78 (diff) | |
merge with pad module and latest trunk too
bzr revid: tta@openerp.com-20120427085103-s2nf391at3nsmbdg
Diffstat (limited to 'addons/pad/static')
| -rw-r--r-- | addons/pad/static/src/js/pad.js | 129 | ||||
| -rw-r--r-- | addons/pad/static/src/xml/pad.xml | 16 |
2 files changed, 144 insertions, 1 deletions
diff --git a/addons/pad/static/src/js/pad.js b/addons/pad/static/src/js/pad.js index 2e5f8820ac4..a4234738fd4 100644 --- a/addons/pad/static/src/js/pad.js +++ b/addons/pad/static/src/js/pad.js @@ -15,4 +15,131 @@ instance.web.Sidebar = instance.web.Sidebar.extend({ } }); -}; +instance.web.form.FieldEtherpad = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, { + template: 'FieldEtherpad', + initialize_content: function() { + this.$textarea = undefined; + this.$element.find('span').text(this.name); + this.$element.find('span').click(_.bind(function(ev){ + this.$element.find('span').toggleClass('etherpad_zoom_head'); + this.$element.find('div').toggleClass('etherpad_zoom'); + $("body").toggleClass('etherpad_body'); + },this)); + if (!this.get("effective_readonly")) { + this.$textarea = this.$element.find('textarea'); + this.$textarea.hide(); + this.$textarea.change(_.bind(function() { + this.set({'value': instance.web.parse_value(this.$textarea.val(), this)}); + }, this)); + this.resized = false; + } + }, + set_value: function(value_) { + var self = this ; + var show_value = instance.web.format_value(value_, this, ''); + var company_id = (self.view.datarecord.hasOwnProperty('id')) ?self.view.datarecord.company_id[0]: self.view.datarecord.company_id ; + new instance.web.DataSet(this, 'res.company', {}).read_ids([company_id],['pad_url_template'],{}).then(function(res){ + var pad_template = res[0].pad_url_template.replace('-%(salt)s-%(name)s','').replace(/\s/g,''); + + var patt_url = (_.str.sprintf(pad_template.replace('-%(id)d',''), { + db : self.session.db, + model : self.view.model, + })).replace(/\s/g,'') ; + + + if(!self.view.datarecord.hasOwnProperty('id')) + { + alert("booom",show_value); + self.add_pad(self,pad_template); + } + else if(self.view.datarecord.hasOwnProperty('id') && show_value.search(patt_url) != 0){ + self.add_pad(self,pad_template); + self.view.do_save(); + } + else + self.show_pad_value(self,value_); + }); + }, + show_pad_value: function(self,value_) + { + self._inhibit_on_change = true; + self.set({'value': value_ }); + self._inhibit_on_change = false; + self.invalid = false; + self.render_value(); + }, + add_pad: function(self,pad_template){ + var url = (_.str.sprintf(pad_template, { + db : self.session.db, + model : self.view.model, + id : Math.round(new Date().getTime()/100.0), + })).replace(/\s/g,''); + self.show_pad_value(self,url + '\n'); + self._dirty_flag = true ; + }, + render_value: function() { + var show_value = instance.web.format_value(this.get('value'), this, ''); + if (!this.get("effective_readonly")) { + this.$textarea.val(show_value); + this.$element.find('div').html('<iframe frameborder="0" height="100%" width="100%" src="'+show_value.split('\n')[0]+'?showChat=false"></iframe>'); + if (!this.resized && this.view.options.resize_textareas) { + this.do_resize(this.view.options.resize_textareas); + this.resized = true; + } + } else { + this.$element.text(show_value); + if(this.get('value') != false) + { + var self = this; + if(show_value.split('\n')[0] != '') + $.get(show_value.split('\n')[0]+'/export/html') + .success(function(data) { self.$element.html(data); }) + .error(function() { self.$element.text('Unable to load pad'); }); + else + self.$element.text(show_value); + } + } + }, + validate: function() { + this.invalid = false; + if (!this.get("effective_readonly")) { + try { + var value_ = instance.web.parse_value(this.$textarea.val(), this, ''); + this.invalid = this.get("required") && value_ === ''; + } catch(e) { + this.invalid = true; + } + } + }, + focus: function($element) { + this._super($element || this.$textarea); + }, + do_resize: function(max_height) { + max_height = parseInt(max_height, 10); + var $input = this.$textarea, + $div = $('<div style="position: absolute; z-index: 1000; top: 0"/>').width($input.width()), + new_height; + $div.text($input.val()); + _.each('font-family,font-size,white-space'.split(','), function(style) { + $div.css(style, $input.css(style)); + }); + $div.appendTo($('body')); + new_height = $div.height(); + if (new_height < 90) { + new_height = 90; + } + if (!isNaN(max_height) && new_height > max_height) { + new_height = max_height; + } + $div.remove(); + $input.height(new_height); + }, + reset: function() { + this.resized = false; + } + })); + + instance.web.form.widgets = instance.web.form.widgets.extend({ + 'etherpad': 'instance.web.form.FieldEtherpad', + }); +}; diff --git a/addons/pad/static/src/xml/pad.xml b/addons/pad/static/src/xml/pad.xml index e922294d03d..66f12b3e241 100644 --- a/addons/pad/static/src/xml/pad.xml +++ b/addons/pad/static/src/xml/pad.xml @@ -2,4 +2,20 @@ <!-- vim:fdl=1: --> <templates id="template" xml:space="preserve"> + +<t t-name="FieldEtherpad"> + <t t-if="!widget.get('effective_readonly')"> + <div class="oe_form_field_text"> + <textarea rows="6" + t-att-name="widget.name" + class="field_text" + t-att-tabindex="widget.node.attrs.tabindex" + t-att-autofocus="widget.node.attrs.autofocus" + ></textarea><img class="oe_field_translate oe_input_icon" t-if="widget.field.translate" t-att-src='_s + "/web/static/src/img/icons/terp-translate.png"' width="16" height="16" border="0"/> + <span class="etherpad_head"></span> + <div class="etherpad_default" ></div> + </div> + </t> +</t> + </templates> |
