wip: moving non wlxml specific extension support from wlxml.js to smartxml.js
[fnpeditor.git] / src / editor / modules / nodePane / nodePane.js
1 define([
2 'libs/text!./template.html',
3 'libs/jquery',
4 'libs/underscore',
5 'modules/nodePane/metaWidget/metaWidget',
6 'utils/wlxml'
7 ], function(templateSrc, $, _, metaWidget, wlxmlUtils) {
8
9 'use strict';
10
11 return function(sandbox) {
12     
13     var view = $(_.template(templateSrc)({tagNames: wlxmlUtils.wlxmlTagNames, classNames: wlxmlUtils.wlxmlClassNames})),
14         currentNode;
15     
16     view.on('change', 'select', function(e) {
17         var target = $(e.target);
18         var attr = target.attr('class').split('-')[3] === 'tagSelect' ? 'Tag' : 'Class',
19             value = target.val().replace(/-/g, '.');
20                 
21         if(attr === 'Class') {
22             //currentNode.document.transform('setClass', {node: currentNode, klass: value});
23             currentNode.transform('smartxml.setAttr', {name: 'class', value: value});
24         }
25         //currentNode['set' + attr](value);
26     });
27    
28     return {
29         start: function() {
30             sandbox.publish('ready');
31         },
32         getView: function() {
33             return view;
34         },
35         setNodeElement: function(wlxmlNodeElement) {
36             var module = this;
37             if(!currentNode) {
38                 wlxmlNodeElement.document.on('change', function(event) {
39                     if(event.type === 'nodeAttrChange' && event.meta.node.sameNode(currentNode)) {
40                         module.setNodeElement(currentNode);
41                     }
42                 });
43             }
44
45             view.find('.rng-module-nodePane-tagSelect').val(wlxmlNodeElement.getTagName());
46
47             var escapedClassName = (wlxmlNodeElement.getClass() || '').replace(/\./g, '-');
48             view.find('.rng-module-nodePane-classSelect').val(escapedClassName);
49
50             var widget = metaWidget.create({attrs:wlxmlNodeElement.getMetaAttributes()});
51             widget.on('valueChanged', function(key, value) {
52                 wlxmlNodeElement.transform('wlxml.setMetaAttribute', {name: key, value: value});
53                 //wlxmlNodeElement.setMetaAttribute(key, value);
54             });
55             view.find('.metaFields').empty().append(widget.el);
56
57             currentNode = wlxmlNodeElement;
58         }
59     };
60     
61 };
62
63 });