editor: dialog forms - setting initial value for text input fields
[fnpeditor.git] / src / editor / modules / documentCanvas / commands.js
index 8ceba63..7302df3 100644 (file)
@@ -1,7 +1,7 @@
 define([
 define([
-'modules/documentCanvas/canvas/documentElement',
-'./canvas/utils'
-], function(documentElement, utils) {
+'./canvas/utils',
+'fnpjs/datetime'
+], function(utils, datetime) {
     
 'use strict';
 
     
 'use strict';
 
@@ -97,7 +97,7 @@ commands.register('list', function(canvas, params) {
 });
 
 commands.register('toggle-grid', function(canvas, params) {
 });
 
 commands.register('toggle-grid', function(canvas, params) {
-    canvas.doc().dom().find('[wlxml-tag]').toggleClass('rng-common-hoveredNode', params.toggle);
+    canvas.doc().dom().parent().toggleClass('grid-on', params.toggle);
     gridToggled = params.toggle;
 });
 
     gridToggled = params.toggle;
 });
 
@@ -109,14 +109,7 @@ commands.register('newNodeRequested', function(canvas, params, user) {
 
     var insertNode = function(insertion) {
         var doc = canvas.wlxmlDocument,
 
     var insertNode = function(insertion) {
         var doc = canvas.wlxmlDocument,
-            node, metadata, creator, currentDate, dt;
-
-        var pad = function(number) {
-            if(number < 10) {
-                number = '0' + number;
-            }
-            return number;
-        };
+            node, metadata, creator;
 
         doc.startTransaction();
         node = insertion();
 
         doc.startTransaction();
         node = insertion();
@@ -130,17 +123,9 @@ commands.register('newNodeRequested', function(canvas, params, user) {
                 creator = 'anonymous';
             }
 
                 creator = 'anonymous';
             }
 
-            currentDate = new Date();
-            dt = pad(currentDate.getDate()) + '-' +
-                            pad((currentDate.getMonth() + 1))  + '-' +
-                            pad(currentDate.getFullYear()) + ' ' +
-                            pad(currentDate.getHours()) + ':' +
-                            pad(currentDate.getMinutes()) + ':' +
-                            pad(currentDate.getSeconds());
-
             metadata = node.getMetadata();
             metadata.add({key: 'creator', value: creator});
             metadata = node.getMetadata();
             metadata.add({key: 'creator', value: creator});
-            metadata.add({key: 'date', value: dt});
+            metadata.add({key: 'date', value: datetime.currentStrfmt()});
         }
         doc.endTransaction();
         return node;
         }
         doc.endTransaction();
         return node;
@@ -191,11 +176,18 @@ commands.register('newNodeRequested', function(canvas, params, user) {
         }
     } else if(canvas.getCurrentNodeElement()) {
         wlxmlNode = canvas.getCurrentNodeElement().data('wlxmlNode');
         }
     } else if(canvas.getCurrentNodeElement()) {
         wlxmlNode = canvas.getCurrentNodeElement().data('wlxmlNode');
-        wrapper = insertNode(function() {
-            return wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}});
-        });
+        if(params.ctrlKey) {
+            wrapper = insertNode(function() {
+                return wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}});
+            });
+        } else {
+            wrapper = insertNode(function() {
+                var node = wlxmlNode.after({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}});
+                node.append({text:''});
+                return node;
+            });
+        }
         canvas.setCurrentElement(utils.findCanvasElement(wrapper));
         canvas.setCurrentElement(utils.findCanvasElement(wrapper));
-
     }
 
 
     }
 
 
@@ -205,14 +197,17 @@ commands.register('footnote', function(canvas, params) {
     void(params);
     var cursor = canvas.getCursor(),
         position = cursor.getPosition(),
     void(params);
     var cursor = canvas.getCursor(),
         position = cursor.getPosition(),
-        asideNode, asideElement;
+        asideNode, asideElement, node;
         
 
     if(cursor.isSelectingWithinElement()) {
         asideNode = position.element.data('wlxmlNode').wrapWith({tagName: 'aside', attrs:{'class': 'footnote'}, start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset});
     } else {
         
 
     if(cursor.isSelectingWithinElement()) {
         asideNode = position.element.data('wlxmlNode').wrapWith({tagName: 'aside', attrs:{'class': 'footnote'}, start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset});
     } else {
-        asideNode = position.element.data('wlxmlNode').divideWithElementNode({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: position.offset});
-        asideNode.append({text: ''});
+        node = position.element.data('wlxmlNode');
+        node.document.transaction(function() {
+            asideNode = node.divideWithElementNode({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: position.offset});
+            asideNode.append({text: ''});
+        });
     }
 
     asideElement = utils.findCanvasElement(asideNode);
     }
 
     asideElement = utils.findCanvasElement(asideNode);