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
=== modified file 'addons/web/__openerp__.py'
--- addons/web/__openerp__.py 2014-03-24 09:30:38 +0000
+++ addons/web/__openerp__.py 2014-04-08 13:23:20 +0000
@@ -44,6 +44,8 @@
44 "static/lib/underscore.string/lib/underscore.string.js",44 "static/lib/underscore.string/lib/underscore.string.js",
45 "static/lib/backbone/backbone.js",45 "static/lib/backbone/backbone.js",
46 "static/lib/cleditor/jquery.cleditor.js",46 "static/lib/cleditor/jquery.cleditor.js",
47 "static/lib/ckeditor/ckeditor.js",
48 "static/lib/ckeditor/adapters/jquery.js",
47 "static/lib/py.js/lib/py.js",49 "static/lib/py.js/lib/py.js",
48 "static/lib/select2/select2.js",50 "static/lib/select2/select2.js",
49 "static/src/js/openerpframework.js",51 "static/src/js/openerpframework.js",
5052
=== modified file 'addons/web/static/src/css/base.css'
--- addons/web/static/src/css/base.css 2014-04-07 16:17:28 +0000
+++ addons/web/static/src/css/base.css 2014-04-08 13:23:20 +0000
@@ -943,7 +943,7 @@
943 background-image: -moz-linear-gradient(top, #fc8787, maroon);943 background-image: -moz-linear-gradient(top, #fc8787, maroon);
944 background-image: -ms-linear-gradient(top, #fc8787, maroon);944 background-image: -ms-linear-gradient(top, #fc8787, maroon);
945 background-image: -o-linear-gradient(top, #fc8787, maroon);945 background-image: -o-linear-gradient(top, #fc8787, maroon);
946 background-image: linear-gradient(to bottom, #fc8787, #800000);946 background-image: linear-gradient(to bottom, #fc8787, maroon);
947}947}
948.openerp .navbar .oe_topbar_anonymous_login a {948.openerp .navbar .oe_topbar_anonymous_login a {
949 display: block;949 display: block;
@@ -3470,6 +3470,23 @@
3470 overflow: hidden !important;3470 overflow: hidden !important;
3471 }3471 }
3472}3472}
3473#upload_file {
3474 margin-left: 317px;
3475}
3476#upload_file #ufile {
3477 display: inline;
3478}
3479
3480.oe_sign {
3481 margin: 5px 5px;
3482 font-size: 16px;
3483}
3484
3485.oe_sign_hover {
3486 border-bottom: solid 1.5px #999999;
3487 background-color: white;
3488}
3489
3473.ui-icon {3490.ui-icon {
3474 width: 18px;3491 width: 18px;
3475 height: 18px;3492 height: 18px;
34763493
=== modified file 'addons/web/static/src/css/base.sass'
--- addons/web/static/src/css/base.sass 2014-04-07 16:17:28 +0000
+++ addons/web/static/src/css/base.sass 2014-04-08 13:23:20 +0000
@@ -506,7 +506,7 @@
506 .oe_grey506 .oe_grey
507 color: #aaa507 color: #aaa
508 // Added for generic error message and customize bootstrap3 <pre>,<hr>508 // Added for generic error message and customize bootstrap3 <pre>,<hr>
509 .oe_error_detail 509 .oe_error_detail
510 hr510 hr
511 display: block511 display: block
512 -webkit-margin-before: 0.5em512 -webkit-margin-before: 0.5em
@@ -642,7 +642,7 @@
642 //Customize label weight according bootstrap3642 //Customize label weight according bootstrap3
643 > label:not([for])643 > label:not([for])
644 font-weight: normal !important644 font-weight: normal !important
645 // End of customize 645 // End of customize
646 div.ui-tabs646 div.ui-tabs
647 padding: 3px 0px 3px 0px647 padding: 3px 0px 3px 0px
648 .ui-tabs-hide648 .ui-tabs-hide
@@ -1230,7 +1230,7 @@
1230 display: none1230 display: none
1231 // }}}1231 // }}}
1232 // FormPopup {{{1232 // FormPopup {{{
1233 .oe_popup_form 1233 .oe_popup_form
1234 .oe_formview .oe_form_pager1234 .oe_formview .oe_form_pager
1235 display: none !important1235 display: none !important
1236 // Customize label weight for popup wizard appear from another wizard according bootstrap31236 // Customize label weight for popup wizard appear from another wizard according bootstrap3
@@ -1264,7 +1264,7 @@
1264 input[type="checkbox"]1264 input[type="checkbox"]
1265 margin: 3px 3px 3px 4px1265 margin: 3px 3px 3px 4px
1266 select1266 select
1267 margin: 2px 4px 2px 0 1267 margin: 2px 4px 2px 0
1268 //End of customize1268 //End of customize
1269 &.oe_focused1269 &.oe_focused
1270 border-color: $tag-border-selected1270 border-color: $tag-border-selected
@@ -1688,8 +1688,8 @@
1688 padding-left: 2px1688 padding-left: 2px
1689 @include vertical-gradient(#fcfcfc, #dedede)1689 @include vertical-gradient(#fcfcfc, #dedede)
1690 > span1690 > span
1691 margin-left: 4px 1691 margin-left: 4px
1692 1692
1693 // }}}1693 // }}}
1694 // FormView.custom tags and classes {{{1694 // FormView.custom tags and classes {{{
1695 .oe_form1695 .oe_form
@@ -2017,7 +2017,7 @@
2017 .oe_e2017 .oe_e
2018 position: relative2018 position: relative
2019 top: -1px2019 top: -1px
2020 left: -9px 2020 left: -9px
2021 input.oe_form_binary_file2021 input.oe_form_binary_file
2022 display: inline-block2022 display: inline-block
2023 margin-left: -85px2023 margin-left: -85px
@@ -2752,7 +2752,7 @@
2752 filter: alpha(opacity = 0)2752 filter: alpha(opacity = 0)
2753 border: none2753 border: none
2754 width: 02754 width: 0
2755 border-right: none 2755 border-right: none
2756 > .label2756 > .label
2757 border-bottom: 1px solid #cacaca2757 border-bottom: 1px solid #cacaca
2758 background: transparent2758 background: transparent
@@ -2805,6 +2805,17 @@
2805 overflow: hidden !important2805 overflow: hidden !important
2806// }}}2806// }}}
28072807
2808// User Signature
2809#upload_file
2810 margin-left: 317px
2811 #ufile
2812 display: inline
2813.oe_sign
2814 margin: 5px 5px
2815 font-size: 16px
2816.oe_sign_hover
2817 border-bottom: solid 1.5px #999
2818 background-color: white
28082819
2809// Hack for ui icon {{{2820// Hack for ui icon {{{
2810.ui-icon2821.ui-icon
28112822
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js 2014-04-07 16:17:28 +0000
+++ addons/web/static/src/js/view_form.js 2014-04-08 13:23:20 +0000
@@ -2718,6 +2718,192 @@
2718 },2718 },
2719});2719});
27202720
2721/**widget for CKEditor */
2722
2723var ckeditor_addFunction_org = CKEDITOR.tools.addFunction;
2724CKEDITOR.tools.addFunction = function(fn, scope)
2725 {
2726 if(scope && scope._ && scope._.attrChanges && scope._.detach)
2727 {
2728 var scope_reference = scope;
2729 return ckeditor_addFunction_org(function()
2730 {
2731 var self = this,
2732 self_arguments=arguments;
2733 setTimeout(function()
2734 {
2735 if(CKEDITOR.instances[self.editor.name])
2736 {
2737 fn.apply(self, self_arguments);
2738 }
2739 }, 0);
2740 }, scope);
2741 }
2742 return ckeditor_addFunction_org(fn, scope);
2743 };
2744
2745CKEDITOR.on('dialogDefinition', function(e)
2746 {
2747 var dialogName = e.data.name;
2748 var dialogDefinition = e.data.definition;
2749 if ( dialogName == 'image' ) {
2750 dialogDefinition.removeContents('advanced');
2751 dialogDefinition.removeContents('Link');
2752 var infoTab = dialogDefinition.getContents('info');
2753 infoTab.remove('ratioLock');
2754 infoTab.remove('txtBorder');
2755 infoTab.remove('txtHSpace');
2756 infoTab.remove('txtVSpace');
2757 infoTab.remove('cmbAlign');
2758 };
2759 _.each(e.data.definition.contents, function(element)
2760 {
2761 if(element.filebrowser!='uploadButton')
2762 {
2763 return
2764 }
2765 _.each(element.elements, function(element)
2766 {
2767 if(!element.onClick || element.type!='fileButton')
2768 {
2769 return
2770 }
2771 var onClick_org = element.onClick;
2772 element.onClick = function(e1)
2773 {
2774 onClick_org.apply(this, arguments);
2775 _.each(jQuery('#'+this.domId).closest('table')
2776 .find('iframe').contents().find(':file')
2777 .get(0).files,
2778 function(file)
2779 {
2780 var reader = new FileReader();
2781 reader.onload = function(load_event)
2782 {
2783 CKEDITOR.tools.callFunction(
2784 e.editor._.filebrowserFn,
2785 load_event.target.result,
2786 '');
2787 }
2788 reader.readAsDataURL(file);
2789 });
2790 return false;
2791 }
2792 });
2793 });
2794 });
2795
2796function filter_html(value, ckeditor_filter, ckeditor_writer)
2797 {
2798 var fragment = CKEDITOR.htmlParser.fragment.fromHtml(value);
2799 ckeditor_filter.applyTo(fragment);
2800 ckeditor_writer.reset();
2801 fragment.writeHtml(ckeditor_writer);
2802 return ckeditor_writer.getHtml();
2803 };
2804default_ckeditor_filter = new CKEDITOR.filter(
2805 {
2806 '*':
2807 {
2808 attributes: 'href,src,style,alt,width,height,dir',
2809 styles: '*',
2810 classes: '*',
2811 },
2812 '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,
2813 });
2814default_ckeditor_writer = new CKEDITOR.htmlParser.basicWriter();
2815
2816instance.web.form.FieldCKEditor = instance.web.form.FieldText.extend({
2817 ckeditor_config: {
2818 removePlugins: 'iframe,flash,forms,smiley,pagebreak,stylescombo',
2819 filebrowserImageUploadUrl: 'dummy',
2820 extraPlugins: 'filebrowser',
2821 image_previewText: CKEDITOR.tools.repeat( 'Image Preview', 1 )
2822 },
2823 ckeditor_filter: default_ckeditor_filter,
2824 ckeditor_writer: default_ckeditor_writer,
2825 start: function()
2826 {
2827 this._super.apply(this, arguments);
2828 CKEDITOR.lang.load(openerp.session.user_context.lang.split('_')[0], 'en', function() {});
2829 },
2830 initialize_content: function()
2831 {
2832 var self = this;
2833 this._super.apply(this, arguments);
2834 if(!this.$textarea)
2835 {
2836 return;
2837 }
2838 this.editor = CKEDITOR.replace(this.$textarea.get(0),
2839 _.extend(
2840 {
2841 language: openerp.session.user_context.lang.split('_')[0],
2842 on:
2843 {
2844 'change': function()
2845 {
2846 self.store_dom_value();
2847 },
2848 },
2849 },
2850 this.ckeditor_config));
2851 },
2852 store_dom_value: function()
2853 {
2854 this.internal_set_value(this.editor ? this.editor.getData() : openerp.web.parse_value(this.get('value'), this));
2855 },
2856 filter_html: function(value)
2857 {
2858 return filter_html(value, this.ckeditor_filter, this.ckeditor_writer);
2859 },
2860 render_value: function()
2861 {
2862 if(this.get("effective_readonly"))
2863 {
2864 this.$el.html(this.filter_html(this.get('value')));
2865 }
2866 else
2867 {
2868 if(this.editor)
2869 {
2870 var self = this;
2871 if(this.editor.status != 'ready')
2872 {
2873 var instanceReady = function()
2874 {
2875 self.editor.setData(self.get('value') || '');
2876 self.editor.removeListener('instanceReady', instanceReady);
2877 };
2878 this.editor.on('instanceReady', instanceReady);
2879 }
2880 else
2881 {
2882 self.editor.setData(self.get('value') || '');
2883 }
2884 }
2885 }
2886 },
2887 undelegateEvents: function()
2888 {
2889 this._cleanup_editor();
2890 return this._super.apply(this, arguments);
2891 },
2892 _cleanup_editor: function()
2893 {
2894 if(this.editor)
2895 {
2896 CKEDITOR.remove(this.editor);
2897 this.editor.removeAllListeners();
2898 this.editor = null;
2899 }
2900 },
2901 destroy_content: function()
2902 {
2903 this._cleanup_editor();
2904 }
2905 });
2906
2721/**2907/**
2722 * FieldTextHtml Widget2908 * FieldTextHtml Widget
2723 * Intended for FieldText widgets meant to display HTML content. This2909 * Intended for FieldText widgets meant to display HTML content. This
@@ -2743,7 +2929,7 @@
2743 controls: // controls to add to the toolbar2929 controls: // controls to add to the toolbar
2744 "bold italic underline strikethrough " +2930 "bold italic underline strikethrough " +
2745 "| removeformat | bullets numbering | outdent " +2931 "| removeformat | bullets numbering | outdent " +
2746 "indent | link unlink | source",2932 "indent | link unlink | source | image",
2747 bodyStyle: // style to assign to document body contained within the editor2933 bodyStyle: // style to assign to document body contained within the editor
2748 "margin:4px; color:#4c4c4c; font-size:13px; font-family:'Lucida Grande',Helvetica,Verdana,Arial,sans-serif; cursor:text"2934 "margin:4px; color:#4c4c4c; font-size:13px; font-family:'Lucida Grande',Helvetica,Verdana,Arial,sans-serif; cursor:text"
2749 });2935 });
@@ -2759,6 +2945,14 @@
2759 .click(this.on_translate);2945 .click(this.on_translate);
2760 this.$cleditor.$toolbar.append($img);2946 this.$cleditor.$toolbar.append($img);
2761 }2947 }
2948 if (this.options.signature){
2949 var $upload_file = $('<div class="cleditorGroup"><div class="cleditorDivider"></div><div class="fa fa-picture-o oe_sign" title="Upload Image"></div></div>')
2950 .click(function(){
2951 $("#upload_file").is(":visible") ? $("#upload_file").hide() : self.on_upload_file();
2952 })
2953 .hover(function() { $(this).toggleClass("oe_sign_hover"); });
2954 this.$cleditor.$toolbar.append($upload_file);
2955 }
2762 }2956 }
2763 },2957 },
2764 render_value: function() {2958 render_value: function() {
@@ -2771,6 +2965,42 @@
2771 this.$el.html(this.get('value'));2965 this.$el.html(this.get('value'));
2772 }2966 }
2773 },2967 },
2968 on_upload_file: function(e) {
2969 var self = this;
2970 $('.cleditorToolbar').after(QWeb.render("UploadFile", {widget: this}));
2971 $("#ufile").change(function(){
2972 var imageType = /image.*/;
2973 var max_image_size = 3 * 1024 * 1024;
2974 if (this.files && this.files[0] && this.files[0].type.match(imageType)) {
2975 if(this.files[0].size < max_image_size){
2976 var reader = new FileReader();
2977 reader.onload = function (e) {
2978 $('#img_preview').attr('src', e.target.result);
2979 }
2980 reader.readAsDataURL(this.files[0]);
2981 $('#upload_file').children().show();
2982 }else{
2983 self.hide_on_warning();
2984 self.do_warn(_t("Invalid image size"), _t("Image is too large to upload."), true);
2985 }
2986 }else{
2987 self.hide_on_warning();
2988 self.do_warn(_t("Invalid file format"), _t("Upload valid image file only."), true);
2989 }
2990 });
2991 $('#submit_ufile').click(function() {
2992 $('#img_preview').appendTo($(".cleditorMain iframe").contents().find('body'));
2993 self.hide_popup(this);
2994 });
2995 },
2996 hide_popup: function(e) {
2997 $(e).parent().hide();
2998 $(".cleditorMain iframe").focus();
2999 },
3000 hide_on_warning: function(e) {
3001 $('#ufile').val('');
3002 $('#submit_ufile, #img_preview').hide();
3003 }
2774});3004});
27753005
2776instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({3006instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({
@@ -5943,7 +6173,7 @@
5943 'email' : 'instance.web.form.FieldEmail',6173 'email' : 'instance.web.form.FieldEmail',
5944 'url' : 'instance.web.form.FieldUrl',6174 'url' : 'instance.web.form.FieldUrl',
5945 'text' : 'instance.web.form.FieldText',6175 'text' : 'instance.web.form.FieldText',
5946 'html' : 'instance.web.form.FieldTextHtml',6176 'html' : 'instance.web.form.FieldCKEditor',
5947 'date' : 'instance.web.form.FieldDate',6177 'date' : 'instance.web.form.FieldDate',
5948 'datetime' : 'instance.web.form.FieldDatetime',6178 'datetime' : 'instance.web.form.FieldDatetime',
5949 'selection' : 'instance.web.form.FieldSelection',6179 'selection' : 'instance.web.form.FieldSelection',