client/js/renderer/edgeeditor.js
changeset 472 6dcff4438175
parent 461 48235ed6b07d
child 466 884b35feb04b
equal deleted inserted replaced
471:e0c7be5dc02c 472:6dcff4438175
    27                     has_creator: !!_model.get("created_by"),
    27                     has_creator: !!_model.get("created_by"),
    28                     title: _model.get("title"),
    28                     title: _model.get("title"),
    29                     uri: _model.get("uri"),
    29                     uri: _model.get("uri"),
    30                     short_uri:  Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
    30                     short_uri:  Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
    31                     description: _model.get("description"),
    31                     description: _model.get("description"),
    32                     color: _model.get("color") || _created_by.get("color"),
    32                     color: (_model.has("style") && _model.get("style").color) || _created_by.get("color"),
       
    33                     dash: _model.has("style") && _model.get("style").dash ? "checked" : "",
       
    34                     arrow: (_model.has("style") && _model.get("style").arrow) || !_model.has("style") || (typeof _model.get("style").arrow === 'undefined') ? "checked" : "",
       
    35                     thickness: (_model.has("style") && _model.get("style").thickness) || 1,
    33                     from_title: _from_model.get("title"),
    36                     from_title: _from_model.get("title"),
    34                     to_title: _to_model.get("title"),
    37                     to_title: _to_model.get("title"),
    35                     from_color: _from_model.get("color") || (_from_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
    38                     from_color: (_from_model.has("style") && _from_model.get("style").color) || (_from_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
    36                     to_color: _to_model.get("color") || (_to_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
    39                     to_color: (_to_model.has("style") && _to_model.get("style").color) || (_to_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
    37                     created_by_color: _created_by.get("color"),
    40                     created_by_color: _created_by.get("color"),
    38                     created_by_title: _created_by.get("title")
    41                     created_by_title: _created_by.get("title")
    39                 },
    42                 },
    40                 renkan: this.renkan,
    43                 renkan: this.renkan,
    41                 shortenText: Utils.shortenText,
    44                 shortenText: Utils.shortenText,
    43             }));
    46             }));
    44             this.redraw();
    47             this.redraw();
    45             var _this = this,
    48             var _this = this,
    46             closeEditor = function() {
    49             closeEditor = function() {
    47                 _this.renderer.removeRepresentation(_this);
    50                 _this.renderer.removeRepresentation(_this);
       
    51                 _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
    48                 paper.view.draw();
    52                 paper.view.draw();
    49             };
    53             };
    50             this.editor_$.find(".Rk-CloseX").click(closeEditor);
    54             this.editor_$.find(".Rk-CloseX").click(closeEditor);
    51             this.editor_$.find(".Rk-Edit-Goto").click(function() {
    55             this.editor_$.find(".Rk-Edit-Goto").click(function() {
    52                 if (!_model.get("uri")) {
    56                 if (!_model.get("uri")) {
    62                             var _data = {
    66                             var _data = {
    63                                 title: _this.editor_$.find(".Rk-Edit-Title").val()
    67                                 title: _this.editor_$.find(".Rk-Edit-Title").val()
    64                             };
    68                             };
    65                             if (_this.options.show_edge_editor_uri) {
    69                             if (_this.options.show_edge_editor_uri) {
    66                                 _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
    70                                 _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
       
    71                             }
       
    72                             if (_this.options.show_node_editor_style) {
       
    73                                 var dash = _this.editor_$.find(".Rk-Edit-Dash").is(':checked');
       
    74                                 _data.style = _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {dash: dash});
       
    75                                 var arrow = _this.editor_$.find(".Rk-Edit-Arrow").is(':checked');
       
    76                                 _data.style = _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {arrow: arrow});
    67                             }
    77                             }
    68                             _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
    78                             _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
    69                             _model.set(_data);
    79                             _model.set(_data);
    70                             paper.view.draw();
    80                             paper.view.draw();
    71                         } else {
    81                         } else {
   121                             _e.preventDefault();
   131                             _e.preventDefault();
   122                             _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
   132                             _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
   123                         },
   133                         },
   124                         function(_e) {
   134                         function(_e) {
   125                             _e.preventDefault();
   135                             _e.preventDefault();
   126                             _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color"));
   136                             _this.editor_$.find(".Rk-Edit-Color").css("background", (_model.has("style") && _model.get("style").color)|| (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color"));
   127                         }
   137                         }
   128                 ).click(function(_e) {
   138                 ).click(function(_e) {
   129                     _e.preventDefault();
   139                     _e.preventDefault();
   130                     if (_this.renderer.isEditable()) {
   140                     if (_this.renderer.isEditable()) {
   131                         _model.set("color", $(this).attr("data-color"));
   141                         _model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {color: $(this).attr("data-color")}));
   132                         _picker.hide();
   142                         _picker.hide();
   133                         paper.view.draw();
   143                         paper.view.draw();
   134                     } else {
   144                     } else {
   135                         closeEditor();
   145                         closeEditor();
   136                     }
   146                     }
       
   147                 });
       
   148                 var shiftThickness = function(n) {
       
   149                     if (_this.renderer.isEditable()) {
       
   150                         var _oldThickness = ((_model.has('style') && _model.get('style').thickness) || 1),
       
   151                             _newThickness = n + _oldThickness;
       
   152                         if(_newThickness < 1 ) {
       
   153                             _newThickness = 1;
       
   154                         }
       
   155                         else if (_newThickness > _this.options.node_stroke_witdh_scale) {
       
   156                             _newThickness = _this.options.node_stroke_witdh_scale;
       
   157                         }
       
   158                         if (_newThickness !== _oldThickness) {
       
   159                             _this.editor_$.find("#Rk-Edit-Thickness-Value").text(_newThickness);
       
   160                             _model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {thickness: _newThickness}));
       
   161                             paper.view.draw();
       
   162                         }
       
   163                     }
       
   164                     else {
       
   165                         closeEditor();
       
   166                     }
       
   167                 };
       
   168 
       
   169                 this.editor_$.find("#Rk-Edit-Thickness-Down").click(function() {
       
   170                     shiftThickness(-1);
       
   171                     return false;
       
   172                 });
       
   173                 this.editor_$.find("#Rk-Edit-Thickness-Up").click(function() {
       
   174                     shiftThickness(1);
       
   175                     return false;
   137                 });
   176                 });
   138             }
   177             }
   139         },
   178         },
   140         redraw: function() {
   179         redraw: function() {
   141             if (this.options.popup_editor){
   180             if (this.options.popup_editor){