integration wip: setting/handling contentSet event (source/canvas)
[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         currentNode['set' + attr](value);
22     });
23     
24     return {
25         start: function() {
26             sandbox.publish('ready');
27         },
28         getView: function() {
29             return view;
30         },
31         setNodeElement: function(wlxmlNodeElement) {
32             view.find('.rng-module-nodePane-tagSelect').val(wlxmlNodeElement.getTagName());
33
34             var escapedClassName = (wlxmlNodeElement.getClass() || '').replace(/\./g, '-')
35             view.find('.rng-module-nodePane-classSelect').val(escapedClassName);
36
37             var widget = metaWidget.create({attrs:wlxmlNodeElement.getMetaAttributes()});
38             widget.on('valueChanged', function(key, value) {
39                 sandbox.publish('nodeElementChange', key, value);
40             });
41             view.find('.metaFields').empty().append(widget.el);
42
43             currentNode = wlxmlNodeElement;
44         }
45     };
46     
47 };
48
49 });