client/js/renderer/nodeeditor.js
changeset 600 e12243191095
parent 530 9823b527c3a1
child 625 4d67ae41b9b3
equal deleted inserted replaced
599:79c59e503f08 600:e12243191095
     1 
     1 
     2 define(['jquery', 'underscore', 'requtils', 'renderer/baseeditor', 'renderer/shapebuilder', 'ckeditor-jquery'], function ($, _, requtils, BaseEditor, ShapeBuilder) {
     2 define(['jquery', 'underscore', 'requtils', 'renderer/baseeditor', 'renderer/shapebuilder', 'ckeditor-core'], function ($, _, requtils, BaseEditor, ShapeBuilder, CKEditor) {
     3     'use strict';
     3     'use strict';
     4 
     4 
     5     var Utils = requtils.getUtils();
     5     var Utils = requtils.getUtils();
     6 
     6 
     7     /* NodeEditor Begin */
     7     /* NodeEditor Begin */
    49                 shapes : _(ShapeBuilder.builders).omit('svg').keys().value(),
    49                 shapes : _(ShapeBuilder.builders).omit('svg').keys().value(),
    50                 types : _(this.options.node_editor_templates).keys().value(),
    50                 types : _(this.options.node_editor_templates).keys().value(),
    51             }));
    51             }));
    52             this.redraw();
    52             this.redraw();
    53             var _this = this,
    53             var _this = this,
    54                 editorInstance = _this.options.show_node_editor_description_richtext ?
    54                 editorInstance = (this.renderer.isEditable()  && _this.options.show_node_editor_description_richtext) ?
    55                     $(".Rk-Edit-Description").ckeditor(_this.options.richtext_editor_config) :
    55                     CKEditor.inline("Rk-Edit-Description-"+_model.get("_id"), _this.options.richtext_editor_config) :
    56                     false,
    56                     false,
    57                 editorInstanceTitle = _this.options.show_node_editor_title_richtext ?
    57                 editorInstanceTitle = (this.renderer.isEditable() && _this.options.show_node_editor_title_richtext) ?
    58                     $(".Rk-Edit-Title").ckeditor(_this.options.richtext_editor_config) :
    58                     CKEditor.inline("Rk-Edit-Title-"+_model.get("_id"), _this.options.richtext_editor_config) :
    59                     false,
    59                     false,
    60                 closeEditor = function() {
    60                 closeEditor = function() {
    61                     _this.renderer.removeRepresentation(_this);
    61                     _this.renderer.removeRepresentation(_this);
    62                     paper.view.draw();
    62                     paper.view.draw();
    63                 };
    63                 };
    72                 _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
    72                 _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
    73                 _this.editor_$.find(".Rk-CloseX").off('click');
    73                 _this.editor_$.find(".Rk-CloseX").off('click');
    74                 _this.editor_$.find(".Rk-Edit-Goto").off('click');
    74                 _this.editor_$.find(".Rk-Edit-Goto").off('click');
    75 
    75 
    76                 if(_this.options.show_node_editor_description_richtext) {
    76                 if(_this.options.show_node_editor_description_richtext) {
    77                     if(typeof editorInstance.editor !== 'undefined') {
    77                     if(editorInstance) {
    78                         var _editor = editorInstance.editor;
    78                         editorInstance.focusManager.blur(true);
    79                         delete editorInstance.editor;
    79                         editorInstance.destroy();
    80                         _editor.focusManager.blur(true);
       
    81                         _editor.destroy();
       
    82                     }
    80                     }
    83                 }
    81                 }
    84                 if(_this.options.show_node_editor_title_richtext) {
    82                 if(_this.options.show_node_editor_title_richtext) {
    85                     if(typeof editorInstanceTitle.editor !== 'undefined') {
    83                     if(editorInstanceTitle) {
    86                         var _editor_title = editorInstanceTitle.editor;
    84                         editorInstanceTitle.focusManager.blur(true);
    87                         delete editorInstanceTitle.editor;
    85                         editorInstanceTitle.destroy();
    88                         _editor_title.focusManager.blur(true);
       
    89                         _editor_title.destroy();
       
    90                     }
    86                     }
    91                 }
    87                 }
    92             };
    88             };
    93 
    89 
    94             this.editor_$.find(".Rk-CloseX").click(function (e) {
    90             this.editor_$.find(".Rk-CloseX").click(function (e) {
   116                             _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
   112                             _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
   117                             _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
   113                             _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
   118                         }
   114                         }
   119                         if (_this.options.show_node_editor_description) {
   115                         if (_this.options.show_node_editor_description) {
   120                             if(_this.options.show_node_editor_description_richtext) {
   116                             if(_this.options.show_node_editor_description_richtext) {
   121                                 if(typeof editorInstance.editor !== 'undefined' &&
   117                                 if(editorInstance &&
   122                                     editorInstance.editor.checkDirty()) {
   118                                     editorInstance.checkDirty()) {
   123                                     _data.description = editorInstance.editor.getData();
   119                                     _data.description = editorInstance.getData();
   124                                     editorInstance.editor.resetDirty();
   120                                     editorInstance.resetDirty();
   125                                 }
   121                                 }
   126                             }
   122                             }
   127                             else {
   123                             else {
   128                                 _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
   124                                 _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
   129                             }
   125                             }
   130                         }
   126                         }
   131                         if (_this.options.show_node_editor_title) {
   127                         if (_this.options.show_node_editor_title) {
   132                             if(_this.options.show_node_editor_title_richtext) {
   128                             if(_this.options.show_node_editor_title_richtext) {
   133                                 if(typeof editorInstanceTitle.editor !== 'undefined' &&
   129                                 if(editorInstanceTitle &&
   134                                         editorInstanceTitle.editor.checkDirty()) {
   130                                         editorInstanceTitle.checkDirty()) {
   135                                     _data.title = editorInstanceTitle.editor.getData();
   131                                     _data.title = editorInstanceTitle.getData();
   136                                     editorInstanceTitle.editor.resetDirty();
   132                                     editorInstanceTitle.resetDirty();
   137                                 }
   133                                 }
   138                             }
   134                             }
   139                             else {
   135                             else {
   140                                 _data.title = _this.editor_$.find(".Rk-Edit-Title").val();
   136                                 _data.title = _this.editor_$.find(".Rk-Edit-Title").val();
   141                             }
   137                             }
   169                 });
   165                 });
   170 
   166 
   171                 this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange);
   167                 this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange);
   172                 if( _this.options.show_node_editor_description &&
   168                 if( _this.options.show_node_editor_description &&
   173                     _this.options.show_node_editor_description_richtext &&
   169                     _this.options.show_node_editor_description_richtext &&
   174                     typeof editorInstance.editor !== 'undefined')
   170                     editorInstance)
   175                 {
   171                 {
   176                     editorInstance.editor.on("change", onFieldChange);
   172                     editorInstance.on("change", onFieldChange);
   177                     editorInstance.editor.on("blur", onFieldChange);
   173                     editorInstance.on("blur", onFieldChange);
   178                 }
   174                 }
   179                 
   175 
   180                 if( _this.options.show_node_editor_title &&
   176                 if( _this.options.show_node_editor_title &&
   181                     _this.options.show_node_editor_title_richtext &&
   177                     _this.options.show_node_editor_title_richtext &&
   182                     typeof editorInstanceTitle.editor !== 'undefined')
   178                     editorInstanceTitle)
   183                 {
   179                 {
   184                     editorInstanceTitle.editor.on("change", onFieldChange);
   180                     editorInstanceTitle.on("change", onFieldChange);
   185                     editorInstanceTitle.editor.on("blur", onFieldChange);
   181                     editorInstanceTitle.on("blur", onFieldChange);
   186                 }
   182                 }
   187 
   183 
   188                 if(_this.options.allow_image_upload) {
   184                 if(_this.options.allow_image_upload) {
   189                     this.editor_$.find(".Rk-Edit-Image-File").change(function() {
   185                     this.editor_$.find(".Rk-Edit-Image-File").change(function() {
   190                         if (this.files.length) {
   186                         if (this.files.length) {