Commits

Lauri Pokka  committed f37cbe1

Inline editing: Restore plus sign after canceling when necessary. Use css for drawing the sign. Fixes also editing of values with extraneous whitespaces in it.

  • Participants
  • Parent commits 0b7269e

Comments (0)

Files changed (2)

File graphingwiki/htdocs/gwikicommon/css/common.css

    Copyright: 2011 by Lauri Pokka
 */
 
-a.jslink {
+.jslink {
     font-size: 12px;
     color: green;
     cursor: pointer;
 }
 
+a.plus:after {
+    content: "+";
+    font-weight: bold;
+    font-size: 1.2em;
+    margin-left: 10px;
+}
+
 .alphabg {
     background: rgba(0, 0, 0, 0.80);
     filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = #CC000000, endColorstr = #CC000000);

File graphingwiki/htdocs/gwikicommon/js/gwiki-common.js

                         value;
                     el.getElements('span.anchor').destroy();
                     if (el.getElement('p')) el = el.getElement('p');
-                    value = el.get('html').clean();
+                    value = el.get('html').trim();
                     if (value !== "" && metas[key].indexOf(value) === -1) value = Object.keyOf(formatted, value);
 
                     //add empty string to meta-object to point empty meta values
             var dt = dd.getPrevious('dt');
 
             dt.grab(new Element('a', {
-                'class': 'jslink',
-                'text': '+',
-                'styles': {
-                    'font-weight': 'bold',
-                    'font-size': '1.1em',
-                    'margin-left': '10px'
-                },
+                'class': 'jslink plus',
                 'events': {
                     'click': function() {
-                        this.destroy();
+                        this.addClass('hidden');
                         dd.set('html', ' ');
                         editValue(dd);
                     }
     });
 
     var getKey = function(dt) {
-        var txt = dt.get('text');
-        var plus = dt.getElement('a.jslink');
-        if (plus) txt = txt.slice(0,txt.length - plus.get('text').length);
-        return txt;
+        return dt.get('text');
     };
 
     var DtKeyCache = null;
             dd.getElements('.waiting').destroy();
         }
 
-        var key = dd.getPrevious('dt').get('text');
-        var index = getMetaIndex(dd.getPrevious('dt'));
+        var keyEl = dd.getPrevious('dt');
+        var key = getKey(keyEl);
+        var index = getMetaIndex(keyEl);
 
         var oldValue = metas[key][index];
 
                     }.bind(this)
                 }).checkAndSend();
             },
+            onCancel: function(){
+                if (oldValue == "") {
+                    dd.set('html', '');
+                    keyEl.getElement('.plus.hidden').removeClass('hidden');
+                }
+            },
             onExit: function() {
                 dd.removeClass('edit');
                 editor = null;
         } else {
             dt.getElements('.waiting').destroy();
         }
-        var key = dt.get('text');
+        var key = getKey(dt);
         var index = getMetaIndex(dt);
 
         if (!metas[key] || metas[key][index] == "") return;
     options: {
         //onSave: function(value){},
         //onExit: function(){}
+        //onCancel: function(){}
         oldValue: "",
         inline: true, //puts all controls on the same row if enabled
         key: null,
 
         if (this.options.key) {
             new Request.JSON({
-                url: '?action=ajaxUtils&util=getProperties&key=' + this.options.key,
+                url: '?action=ajaxUtils&util=getProperties&key=' + encodeURIComponent(this.options.key),
                 onComplete: function(json) {
                     this._keyProperties = Object.merge(this._keyProperties, json);
                     this.build();
         this.element.empty();
         this.element.set('html', this.element.retrieve('html'));
         this._clean();
+        this.fireEvent('cancel');
         this.fireEvent('exit');
     }
 });