define([
'libs/jquery',
'libs/underscore',
-'modules/documentCanvas/classAttributes',
'modules/documentCanvas/canvas/utils',
'modules/documentCanvas/canvas/widgets',
'modules/documentCanvas/canvas/wlxmlManagers'
-], function($, _, classAttributes, utils, widgets, wlxmlManagers) {
+], function($, _, utils, widgets, wlxmlManagers) {
'use strict';
element.setWlxml({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()});
- _.keys(wlxmlNode.getMetaAttributes()).forEach(function(key) {
- element.setWlxmlMetaAttr(key, params.meta[key]);
- });
-
wlxmlNode.contents().forEach((function(node) {
container.append(DocumentElement.create(node).dom());
}).bind(this));
setWlxmlClass: function(klass) {
if(klass === this.getWlxmlClass())
return;
-
- this.getWlxmlMetaAttrs().forEach(function(attr) {
- if(!classAttributes.hasMetaAttr(klass, attr.name))
- this.dom().removeAttr('wlxml-meta-' + attr.name);
- }, this);
-
if(klass)
this._container().attr('wlxml-class', klass.replace(/\./g, '-'));
else
return true;
return false;
},
-
- getWlxmlMetaAttr: function(attr) {
- return this.dom().attr('wlxml-meta-'+attr);
- },
-
- getWlxmlMetaAttrs: function() {
- var toret = [];
- var attrList = classAttributes.getMetaAttrsList(this.getWlxmlClass());
- attrList.all.forEach(function(attr) {
- toret.push({name: attr.name, value: this.getWlxmlMetaAttr(attr.name) || ''});
- }, this);
- return toret;
- },
-
- setWlxmlMetaAttr: function(attr, value) {
- this.dom().attr('wlxml-meta-'+attr, value);
- },
-
toggleLabel: function(toggle) {
var displayCss = toggle ? 'inline-block' : 'none';
var label = this.dom().children('.canvas-widgets').find('.canvas-widget-label');
+++ /dev/null
-define([], function() {
-
-'use strict';
-
-var wlxmlDict = {
- 'uri': {
- 'uri': 'string'
- }
-};
-
-var hasMetaAttr = function(klass, attrName, dict) {
- dict = dict || wlxmlDict;
- if(!klass)
- return false;
-
- var parts = klass.split('.');
- var partialClass = '';
- for(var i = 0; i < parts.length; i++) {
- partialClass += (partialClass === '' ? '' : '.') + parts[i];
- if(dict[partialClass] && dict[partialClass][attrName])
- return true;
- }
- return false;
-};
-
-var getMetaAttrsList = function(klass, dict) {
- dict = dict || wlxmlDict;
- klass = klass || '';
-
- var toret = {own: [], inheritedFrom: {}, all: []};
- var parts = klass.split('.');
- var partialClass = '';
-
- var generate = function(klass) {
- var toret = [],
- desc = dict[klass];
-
- if(!desc)
- return toret;
-
- _.keys(desc).forEach(function(key) {
- toret.push({name: key, type: desc[key]});
- });
- return toret;
- };
-
- toret.own = generate(klass);
- for(var i = 0; i < parts.length; i++) {
- partialClass += (partialClass === '' ? '' : '.') + parts[i];
- var list = generate(partialClass);
- if(list.length > 0) {
- toret.inheritedFrom[partialClass] = generate(partialClass);
- toret.all = toret.all.concat(toret.inheritedFrom[partialClass]);
- }
- }
- return toret;
-};
-
-return {
- hasMetaAttr: hasMetaAttr,
- getMetaAttrsList: getMetaAttrsList
-};
-
-});
\ No newline at end of file
+++ /dev/null
-define([
-'libs/chai',
-'modules/documentCanvas/classAttributes'
-], function(chai, classAttributes) {
-
-var stubDict = {
- 'klass': {
- 'prop': 'string'
- },
- 'klass.sub1': {
- 'prop1': 'string'
- },
- 'klass.sub1.sub2': {
- 'prop2': 'string'
- }
-};
-
-var assert = chai.assert;
-
-describe('Class attributes', function() {
- it('class has own attribute', function() {
- assert.ok(classAttributes.hasMetaAttr('klass.sub1.sub2', 'prop2', stubDict));
- });
-
- it('class has attributes from parent classes', function() {
- assert.ok(classAttributes.hasMetaAttr('klass.sub1.sub2', 'prop', stubDict));
- assert.ok(classAttributes.hasMetaAttr('klass.sub1.sub2', 'prop1', stubDict));
- });
-
- it('list of class meta attributes', function() {
- var attrList = classAttributes.getMetaAttrsList('klass.sub1.sub2', stubDict);
-
- assert.deepEqual(attrList.own, [{name: 'prop2', type: 'string'}]);
- assert.deepEqual(attrList.inheritedFrom['klass.sub1'], [{name: 'prop1', type: 'string'}]);
- assert.deepEqual(attrList.inheritedFrom.klass, [{name: 'prop', type: 'string'}]);
- assert.deepEqual(attrList.all.sort(), [
- {name: 'prop', type: 'string'},
- {name: 'prop1', type: 'string'},
- {name: 'prop2', type: 'string'}
- ].sort(), 'all values');
- });
-
- it('class without meta attrs', function() {
- var attrList = classAttributes.getMetaAttrsList('some.class', {});
- assert.deepEqual(attrList.own, [], 'empty own list');
- assert.deepEqual(attrList.inheritedFrom, {}, 'empty inherited dict');
- assert.deepEqual(attrList.all, [], 'empty all list');
- });
-
- it('empty class', function() {
- var attrList = classAttributes.getMetaAttrsList('', {});
- assert.deepEqual(attrList.own, [], 'empty own list');
- assert.deepEqual(attrList.inheritedFrom, {}, 'empty inherited dict');
- assert.deepEqual(attrList.all, [], 'empty all list');
- });
-});
-
-});
\ No newline at end of file