Merge lp:~openerp-dev/openerp-web/trunk-user-signature-ima into lp:openerp-web

Proposed by Vidhin Mehta (OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openerp-web/trunk-user-signature-ima
Merge into: lp:openerp-web
Diff against target: 409 lines (+271/-11)
4 files modified
addons/web/__openerp__.py (+2/-0)
addons/web/static/src/css/base.css (+18/-1)
addons/web/static/src/css/base.sass (+19/-8)
addons/web/static/src/js/view_form.js (+232/-2)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/trunk-user-signature-ima
Reviewer Review Type Date Requested Status
OpenERP R&D Web Team Pending
Review via email: mp+201903@code.launchpad.net
To post a comment you must log in.
3902. By Mahendra Barad(OpenERP)

[IMP]added ckeditor lib and replace widget html by ck editor

3903. By Mahendra Barad(OpenERP)

[IMP]improved base path

3904. By Kunal Chavda

[MERGE]with latest and resolve conflicts.

3905. By Jaysinh Shukla(OpenERP)

[MERGE]: merged with web

Unmerged revisions

3905. By Jaysinh Shukla(OpenERP)

[MERGE]: merged with web

3904. By Kunal Chavda

[MERGE]with latest and resolve conflicts.

3903. By Mahendra Barad(OpenERP)

[IMP]improved base path

3902. By Mahendra Barad(OpenERP)

[IMP]added ckeditor lib and replace widget html by ck editor

3901. By Vidhin Mehta (OpenERP)

[MERGE]Truni.

3900. By Ishwar Malvi(OpenERP)

[IMP]improved code for attachement icon in user signature.

3899. By Ishwar Malvi(OpenERP)

[MERGE]with trunk.

3898. By Ishwar Malvi(OpenERP)

[IMP]improved code to hide img_preview and submit button.

3897. By Ishwar Malvi(OpenERP)

[REM]removed unused whitespace.

3896. By Ishwar Malvi(OpenERP)

[IMP]improved code to implement security to upload only image file with size validation.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/__openerp__.py'
2--- addons/web/__openerp__.py 2014-03-24 09:30:38 +0000
3+++ addons/web/__openerp__.py 2014-04-08 13:23:20 +0000
4@@ -44,6 +44,8 @@
5 "static/lib/underscore.string/lib/underscore.string.js",
6 "static/lib/backbone/backbone.js",
7 "static/lib/cleditor/jquery.cleditor.js",
8+ "static/lib/ckeditor/ckeditor.js",
9+ "static/lib/ckeditor/adapters/jquery.js",
10 "static/lib/py.js/lib/py.js",
11 "static/lib/select2/select2.js",
12 "static/src/js/openerpframework.js",
13
14=== modified file 'addons/web/static/src/css/base.css'
15--- addons/web/static/src/css/base.css 2014-04-07 16:17:28 +0000
16+++ addons/web/static/src/css/base.css 2014-04-08 13:23:20 +0000
17@@ -943,7 +943,7 @@
18 background-image: -moz-linear-gradient(top, #fc8787, maroon);
19 background-image: -ms-linear-gradient(top, #fc8787, maroon);
20 background-image: -o-linear-gradient(top, #fc8787, maroon);
21- background-image: linear-gradient(to bottom, #fc8787, #800000);
22+ background-image: linear-gradient(to bottom, #fc8787, maroon);
23 }
24 .openerp .navbar .oe_topbar_anonymous_login a {
25 display: block;
26@@ -3470,6 +3470,23 @@
27 overflow: hidden !important;
28 }
29 }
30+#upload_file {
31+ margin-left: 317px;
32+}
33+#upload_file #ufile {
34+ display: inline;
35+}
36+
37+.oe_sign {
38+ margin: 5px 5px;
39+ font-size: 16px;
40+}
41+
42+.oe_sign_hover {
43+ border-bottom: solid 1.5px #999999;
44+ background-color: white;
45+}
46+
47 .ui-icon {
48 width: 18px;
49 height: 18px;
50
51=== modified file 'addons/web/static/src/css/base.sass'
52--- addons/web/static/src/css/base.sass 2014-04-07 16:17:28 +0000
53+++ addons/web/static/src/css/base.sass 2014-04-08 13:23:20 +0000
54@@ -506,7 +506,7 @@
55 .oe_grey
56 color: #aaa
57 // Added for generic error message and customize bootstrap3 <pre>,<hr>
58- .oe_error_detail
59+ .oe_error_detail
60 hr
61 display: block
62 -webkit-margin-before: 0.5em
63@@ -642,7 +642,7 @@
64 //Customize label weight according bootstrap3
65 > label:not([for])
66 font-weight: normal !important
67- // End of customize
68+ // End of customize
69 div.ui-tabs
70 padding: 3px 0px 3px 0px
71 .ui-tabs-hide
72@@ -1230,7 +1230,7 @@
73 display: none
74 // }}}
75 // FormPopup {{{
76- .oe_popup_form
77+ .oe_popup_form
78 .oe_formview .oe_form_pager
79 display: none !important
80 // Customize label weight for popup wizard appear from another wizard according bootstrap3
81@@ -1264,7 +1264,7 @@
82 input[type="checkbox"]
83 margin: 3px 3px 3px 4px
84 select
85- margin: 2px 4px 2px 0
86+ margin: 2px 4px 2px 0
87 //End of customize
88 &.oe_focused
89 border-color: $tag-border-selected
90@@ -1688,8 +1688,8 @@
91 padding-left: 2px
92 @include vertical-gradient(#fcfcfc, #dedede)
93 > span
94- margin-left: 4px
95-
96+ margin-left: 4px
97+
98 // }}}
99 // FormView.custom tags and classes {{{
100 .oe_form
101@@ -2017,7 +2017,7 @@
102 .oe_e
103 position: relative
104 top: -1px
105- left: -9px
106+ left: -9px
107 input.oe_form_binary_file
108 display: inline-block
109 margin-left: -85px
110@@ -2752,7 +2752,7 @@
111 filter: alpha(opacity = 0)
112 border: none
113 width: 0
114- border-right: none
115+ border-right: none
116 > .label
117 border-bottom: 1px solid #cacaca
118 background: transparent
119@@ -2805,6 +2805,17 @@
120 overflow: hidden !important
121 // }}}
122
123+// User Signature
124+#upload_file
125+ margin-left: 317px
126+ #ufile
127+ display: inline
128+.oe_sign
129+ margin: 5px 5px
130+ font-size: 16px
131+.oe_sign_hover
132+ border-bottom: solid 1.5px #999
133+ background-color: white
134
135 // Hack for ui icon {{{
136 .ui-icon
137
138=== modified file 'addons/web/static/src/js/view_form.js'
139--- addons/web/static/src/js/view_form.js 2014-04-07 16:17:28 +0000
140+++ addons/web/static/src/js/view_form.js 2014-04-08 13:23:20 +0000
141@@ -2718,6 +2718,192 @@
142 },
143 });
144
145+/**widget for CKEditor */
146+
147+var ckeditor_addFunction_org = CKEDITOR.tools.addFunction;
148+CKEDITOR.tools.addFunction = function(fn, scope)
149+ {
150+ if(scope && scope._ && scope._.attrChanges && scope._.detach)
151+ {
152+ var scope_reference = scope;
153+ return ckeditor_addFunction_org(function()
154+ {
155+ var self = this,
156+ self_arguments=arguments;
157+ setTimeout(function()
158+ {
159+ if(CKEDITOR.instances[self.editor.name])
160+ {
161+ fn.apply(self, self_arguments);
162+ }
163+ }, 0);
164+ }, scope);
165+ }
166+ return ckeditor_addFunction_org(fn, scope);
167+ };
168+
169+CKEDITOR.on('dialogDefinition', function(e)
170+ {
171+ var dialogName = e.data.name;
172+ var dialogDefinition = e.data.definition;
173+ if ( dialogName == 'image' ) {
174+ dialogDefinition.removeContents('advanced');
175+ dialogDefinition.removeContents('Link');
176+ var infoTab = dialogDefinition.getContents('info');
177+ infoTab.remove('ratioLock');
178+ infoTab.remove('txtBorder');
179+ infoTab.remove('txtHSpace');
180+ infoTab.remove('txtVSpace');
181+ infoTab.remove('cmbAlign');
182+ };
183+ _.each(e.data.definition.contents, function(element)
184+ {
185+ if(element.filebrowser!='uploadButton')
186+ {
187+ return
188+ }
189+ _.each(element.elements, function(element)
190+ {
191+ if(!element.onClick || element.type!='fileButton')
192+ {
193+ return
194+ }
195+ var onClick_org = element.onClick;
196+ element.onClick = function(e1)
197+ {
198+ onClick_org.apply(this, arguments);
199+ _.each(jQuery('#'+this.domId).closest('table')
200+ .find('iframe').contents().find(':file')
201+ .get(0).files,
202+ function(file)
203+ {
204+ var reader = new FileReader();
205+ reader.onload = function(load_event)
206+ {
207+ CKEDITOR.tools.callFunction(
208+ e.editor._.filebrowserFn,
209+ load_event.target.result,
210+ '');
211+ }
212+ reader.readAsDataURL(file);
213+ });
214+ return false;
215+ }
216+ });
217+ });
218+ });
219+
220+function filter_html(value, ckeditor_filter, ckeditor_writer)
221+ {
222+ var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
223+ ckeditor_filter.applyTo(fragment);
224+ ckeditor_writer.reset();
225+ fragment.writeHtml(ckeditor_writer);
226+ return ckeditor_writer.getHtml();
227+ };
228+default_ckeditor_filter = new CKEDITOR.filter(
229+ {
230+ '*':
231+ {
232+ attributes: 'href,src,style,alt,width,height,dir',
233+ styles: '*',
234+ classes: '*',
235+ },
236+ 'html head title meta style body p div span a h1 h2 h3 h4 h5 img br hr table tr th td ul ol li dd dt strong pre b i': true,
237+ });
238+default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
239+
240+instance.web.form.FieldCKEditor = instance.web.form.FieldText.extend({
241+ ckeditor_config: {
242+ removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo',
243+ filebrowserImageUploadUrl: 'dummy',
244+ extraPlugins: 'filebrowser',
245+ image_previewText: CKEDITOR.tools.repeat( 'Image Preview', 1 )
246+ },
247+ ckeditor_filter: default_ckeditor_filter,
248+ ckeditor_writer: default_ckeditor_writer,
249+ start: function()
250+ {
251+ this._super.apply(this, arguments);
252+ CKEDITOR.lang.load(openerp.session.user_context.lang.split('_')[0], 'en', function() {});
253+ },
254+ initialize_content: function()
255+ {
256+ var self = this;
257+ this._super.apply(this, arguments);
258+ if(!this.$textarea)
259+ {
260+ return;
261+ }
262+ this.editor = CKEDITOR.replace(this.$textarea.get(0),
263+ _.extend(
264+ {
265+ language: openerp.session.user_context.lang.split('_')[0],
266+ on:
267+ {
268+ 'change': function()
269+ {
270+ self.store_dom_value();
271+ },
272+ },
273+ },
274+ this.ckeditor_config));
275+ },
276+ store_dom_value: function()
277+ {
278+ this.internal_set_value(this.editor ? this.editor.getData() : openerp.web.parse_value(this.get('value'), this));
279+ },
280+ filter_html: function(value)
281+ {
282+ return filter_html(value, this.ckeditor_filter, this.ckeditor_writer);
283+ },
284+ render_value: function()
285+ {
286+ if(this.get("effective_readonly"))
287+ {
288+ this.$el.html(this.filter_html(this.get('value')));
289+ }
290+ else
291+ {
292+ if(this.editor)
293+ {
294+ var self = this;
295+ if(this.editor.status != 'ready')
296+ {
297+ var instanceReady = function()
298+ {
299+ self.editor.setData(self.get('value') || '');
300+ self.editor.removeListener('instanceReady', instanceReady);
301+ };
302+ this.editor.on('instanceReady', instanceReady);
303+ }
304+ else
305+ {
306+ self.editor.setData(self.get('value') || '');
307+ }
308+ }
309+ }
310+ },
311+ undelegateEvents: function()
312+ {
313+ this._cleanup_editor();
314+ return this._super.apply(this, arguments);
315+ },
316+ _cleanup_editor: function()
317+ {
318+ if(this.editor)
319+ {
320+ CKEDITOR.remove(this.editor);
321+ this.editor.removeAllListeners();
322+ this.editor = null;
323+ }
324+ },
325+ destroy_content: function()
326+ {
327+ this._cleanup_editor();
328+ }
329+ });
330+
331 /**
332 * FieldTextHtml Widget
333 * Intended for FieldText widgets meant to display HTML content. This
334@@ -2743,7 +2929,7 @@
335 controls: // controls to add to the toolbar
336 "bold italic underline strikethrough " +
337 "| removeformat | bullets numbering | outdent " +
338- "indent | link unlink | source",
339+ "indent | link unlink | source | image",
340 bodyStyle: // style to assign to document body contained within the editor
341 "margin:4px; color:#4c4c4c; font-size:13px; font-family:'Lucida Grande',Helvetica,Verdana,Arial,sans-serif; cursor:text"
342 });
343@@ -2759,6 +2945,14 @@
344 .click(this.on_translate);
345 this.$cleditor.$toolbar.append($img);
346 }
347+ if (this.options.signature){
348+ var $upload_file = $('<div class="cleditorGroup"><div class="cleditorDivider"></div><div class="fa fa-picture-o oe_sign" title="Upload Image"></div></div>')
349+ .click(function(){
350+ $("#upload_file").is(":visible") ? $("#upload_file").hide() : self.on_upload_file();
351+ })
352+ .hover(function() { $(this).toggleClass("oe_sign_hover"); });
353+ this.$cleditor.$toolbar.append($upload_file);
354+ }
355 }
356 },
357 render_value: function() {
358@@ -2771,6 +2965,42 @@
359 this.$el.html(this.get('value'));
360 }
361 },
362+ on_upload_file: function(e) {
363+ var self = this;
364+ $('.cleditorToolbar').after(QWeb.render("UploadFile", {widget: this}));
365+ $("#ufile").change(function(){
366+ var imageType = /image.*/;
367+ var max_image_size = 3 * 1024 * 1024;
368+ if (this.files && this.files[0] && this.files[0].type.match(imageType)) {
369+ if(this.files[0].size < max_image_size){
370+ var reader = new FileReader();
371+ reader.onload = function (e) {
372+ $('#img_preview').attr('src', e.target.result);
373+ }
374+ reader.readAsDataURL(this.files[0]);
375+ $('#upload_file').children().show();
376+ }else{
377+ self.hide_on_warning();
378+ self.do_warn(_t("Invalid image size"), _t("Image is too large to upload."), true);
379+ }
380+ }else{
381+ self.hide_on_warning();
382+ self.do_warn(_t("Invalid file format"), _t("Upload valid image file only."), true);
383+ }
384+ });
385+ $('#submit_ufile').click(function() {
386+ $('#img_preview').appendTo($(".cleditorMain iframe").contents().find('body'));
387+ self.hide_popup(this);
388+ });
389+ },
390+ hide_popup: function(e) {
391+ $(e).parent().hide();
392+ $(".cleditorMain iframe").focus();
393+ },
394+ hide_on_warning: function(e) {
395+ $('#ufile').val('');
396+ $('#submit_ufile, #img_preview').hide();
397+ }
398 });
399
400 instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({
401@@ -5943,7 +6173,7 @@
402 'email' : 'instance.web.form.FieldEmail',
403 'url' : 'instance.web.form.FieldUrl',
404 'text' : 'instance.web.form.FieldText',
405- 'html' : 'instance.web.form.FieldTextHtml',
406+ 'html' : 'instance.web.form.FieldCKEditor',
407 'date' : 'instance.web.form.FieldDate',
408 'datetime' : 'instance.web.form.FieldDatetime',
409 'selection' : 'instance.web.form.FieldSelection',