Browse Source

Hide sectors in Style Manager if all properties are hidden

pull/79/merge
Artur Arseniev 9 years ago
parent
commit
a3c87fda7b
  1. 115
      src/style_manager/model/Property.js
  2. 38
      src/style_manager/model/Sector.js
  3. 23
      src/style_manager/view/PropertyView.js
  4. 175
      src/style_manager/view/SectorView.js

115
src/style_manager/model/Property.js

@ -1,69 +1,70 @@
define(['backbone', './Layers', 'require'],
function(Backbone, Layers, require) {
function(Backbone, Layers, require) {
return Backbone.Model.extend({
return Backbone.Model.extend({
defaults: {
name: '',
property: '',
type: '',
units: [],
unit: '',
defaults: '',
info: '',
value: '',
icon: '',
preview: false,
detached: false,
functionName: '',
properties: [],
layers: [],
list: [],
fixedValues: ['initial', 'inherit'],
},
defaults: {
name: '',
property: '',
type: '',
units: [],
unit: '',
defaults: '',
info: '',
value: '',
icon: '',
preview: false,
detached: false,
visible: true,
functionName: '',
properties: [],
layers: [],
list: [],
fixedValues: ['initial', 'inherit'],
},
initialize: function(opt) {
var o = opt || {};
var type = this.get('type');
var name = this.get('name');
var prop = this.get('property');
var props = this.get('properties');
initialize: function(opt) {
var o = opt || {};
var type = this.get('type');
var name = this.get('name');
var prop = this.get('property');
var props = this.get('properties');
if(!name)
this.set('name', prop.charAt(0).toUpperCase() + prop.slice(1).replace(/-/g,' '));
if(!name)
this.set('name', prop.charAt(0).toUpperCase() + prop.slice(1).replace(/-/g,' '));
if(props.length){
var Properties = require('./Properties');
this.set('properties', new Properties(props));
}
if(props.length){
var Properties = require('./Properties');
this.set('properties', new Properties(props));
}
switch(type){
case 'stack':
this.set('layers', new Layers());
break;
}
},
switch(type){
case 'stack':
this.set('layers', new Layers());
break;
}
},
/**
* Return value
* @return {string} Value
* @private
*/
getValue: function() {
var result = '';
var type = this.get('type');
/**
* Return value
* @return {string} Value
* @private
*/
getValue: function() {
var result = '';
var type = this.get('type');
switch(type){
case 'integer':
result = this.get('value') + this.get('unit');
break;
default:
result = this.get('value');
break;
}
switch(type){
case 'integer':
result = this.get('value') + this.get('unit');
break;
default:
result = this.get('value');
break;
}
return result;
},
return result;
},
});
});
});

38
src/style_manager/model/Sector.js

@ -1,16 +1,16 @@
define(['backbone', './Properties', './PropertyFactory'],
function(Backbone, Properties, PropertyFactory) {
function(Backbone, Properties, PropertyFactory) {
return Backbone.Model.extend({
return Backbone.Model.extend({
defaults: {
id: '',
name: '',
open: true,
defaults: {
id: '',
name: '',
open: true,
buildProps: '',
extendBuilded: 1,
properties : [],
},
properties : [],
},
initialize: function(opts) {
var o = opts || {};
@ -22,7 +22,9 @@ define(['backbone', './Properties', './PropertyFactory'],
else
props = this.extendProperties(builded);
this.set('properties', new Properties(props));
var propsModel = new Properties(props);
propsModel.sector = this;
this.set('properties', propsModel);
},
/**
@ -37,7 +39,7 @@ define(['backbone', './Properties', './PropertyFactory'],
var pLen = props.length;
var mProps = moProps || this.get('properties');
var ext = this.get('extendBuilded');
var isolated = [];
var isolated = [];
for (var i = 0, len = mProps.length; i < len; i++){
var mProp = mProps[i];
@ -46,13 +48,13 @@ define(['backbone', './Properties', './PropertyFactory'],
for(var j = 0; j < pLen; j++){
var prop = props[j];
if(mProp.property == prop.property){
// Check for nested properties
var mPProps = mProp.properties;
if(mPProps && mPProps.length){
mProp.properties = this.extendProperties(prop.properties, mPProps, 1);
}
// Check for nested properties
var mPProps = mProp.properties;
if(mPProps && mPProps.length){
mProp.properties = this.extendProperties(prop.properties, mPProps, 1);
}
props[j] = ext ? _.extend(prop, mProp) : mProp;
isolated[j] = props[j];
isolated[j] = props[j];
found = 1;
continue;
}
@ -60,8 +62,8 @@ define(['backbone', './Properties', './PropertyFactory'],
if(!found){
props.push(mProp);
isolated.push(mProp);
}
isolated.push(mProp);
}
}
return ex ? isolated : props;

23
src/style_manager/view/PropertyView.js

@ -25,14 +25,16 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat
this.input = this.$input = null;
this.className = this.pfx + 'property';
this.inputHolderId = '#' + this.pfx + 'input-holder';
this.sector = this.model.collection.sector;
if(!this.model.get('value'))
this.model.set('value', this.model.get('defaults'));
this.listenTo(this.propTarget, 'update', this.targetUpdated);
this.listenTo(this.model, 'destroy remove', this.remove);
this.listenTo( this.propTarget, 'update', this.targetUpdated);
this.listenTo( this.model ,'change:value', this.valueChanged);
this.listenTo( this.model ,'targetUpdated', this.targetUpdated);
this.listenTo(this.model,'change:value', this.valueChanged);
this.listenTo(this.model,'targetUpdated', this.targetUpdated);
this.listenTo(this.model,'change:visible', this.updateVisibility);
},
/**
@ -56,7 +58,7 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat
/**
* Fired when the target is updated
* */
targetUpdated: function(){
targetUpdated: function() {
this.selectedComponent = this.propTarget.model;
this.helperComponent = this.propTarget.helper;
@ -67,6 +69,10 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat
} else {
this.show();
}
// Sector is not passed to Composite and Stack types
if (this.sector) {
this.sector.trigger('updateVisibility');
}
}
if(this.getTarget()){
@ -270,12 +276,17 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat
this.model.set({value: v}, {silent: true});
},
updateVisibility: function() {
this.el.style.display = this.model.get('visible') ?
'block' : 'none';
},
show: function () {
this.el.style.display = 'block';
this.model.set('visible', 1);
},
hide: function () {
this.el.style.display = 'none';
this.model.set('visible', 0);
},
renderLabel: function(){

175
src/style_manager/view/SectorView.js

@ -1,93 +1,106 @@
define(['backbone', './PropertiesView', 'text!./../templates/sector.html'],
function (Backbone, PropertiesView, sectorTemplate) {
/**
* @class SectorView
* */
return Backbone.View.extend({
function (Backbone, PropertiesView, sectorTemplate) {
/**
* @class SectorView
* */
return Backbone.View.extend({
template: _.template(sectorTemplate),
template: _.template(sectorTemplate),
events:{},
events:{},
initialize: function(o) {
this.config = o.config || {};
this.pfx = this.config.stylePrefix || '';
this.target = o.target || {};
this.propTarget = o.propTarget || {};
this.open = this.model.get('open');
this.caretR = 'fa-caret-right';
this.caretD = 'fa-caret-down';
this.listenTo( this.model ,'change:open', this.updateOpen);
this.events['click .' + this.pfx + 'title'] = 'toggle';
this.delegateEvents();
},
initialize: function(o) {
this.config = o.config || {};
this.pfx = this.config.stylePrefix || '';
this.target = o.target || {};
this.propTarget = o.propTarget || {};
this.open = this.model.get('open');
this.caretR = 'fa-caret-right';
this.caretD = 'fa-caret-down';
this.listenTo(this.model, 'change:open', this.updateOpen);
this.listenTo(this.model, 'updateVisibility', this.updateVisibility);
this.events['click .' + this.pfx + 'title'] = 'toggle';
this.delegateEvents();
},
/**
* Update visibility
*/
updateOpen: function()
{
if(this.model.get('open'))
this.show();
else
this.hide();
},
/**
* If all properties are hidden this will hide the sector
*/
updateVisibility: function () {
var show;
this.model.get('properties').each(function(prop) {
if (prop.get('visible'))
show = 1;
});
this.el.style.display = show ? 'block' : 'none';
},
/**
* Show the content of the sector
* */
show : function()
{
this.$el.addClass(this.pfx + "open");
this.$el.find('.' + this.pfx + 'properties').show();
this.$caret.removeClass(this.caretR).addClass(this.caretD);
},
/**
* Update visibility
*/
updateOpen: function()
{
if(this.model.get('open'))
this.show();
else
this.hide();
},
/**
* Hide the content of the sector
* */
hide : function()
{
this.$el.removeClass(this.pfx + "open");
this.$el.find('.' + this.pfx + 'properties').hide();
this.$caret.removeClass(this.caretD).addClass(this.caretR);
},
/**
* Show the content of the sector
* */
show : function()
{
this.$el.addClass(this.pfx + "open");
this.$el.find('.' + this.pfx + 'properties').show();
this.$caret.removeClass(this.caretR).addClass(this.caretD);
},
/**
* Toggle visibility
* */
toggle: function()
{
var v = this.model.get('open') ? 0 : 1;
this.model.set('open', v);
},
/**
* Hide the content of the sector
* */
hide : function()
{
this.$el.removeClass(this.pfx + "open");
this.$el.find('.' + this.pfx + 'properties').hide();
this.$caret.removeClass(this.caretD).addClass(this.caretR);
},
render : function()
{
this.$el.html(this.template({
pfx: this.pfx,
label: this.model.get('name'),
}));
this.$caret = this.$el.find('#' + this.pfx + 'caret');
this.renderProperties();
this.$el.attr('class', this.pfx + 'sector no-select');
this.updateOpen();
return this;
},
/**
* Toggle visibility
* */
toggle: function()
{
var v = this.model.get('open') ? 0 : 1;
this.model.set('open', v);
},
renderProperties: function()
{
var objs = this.model.get('properties');
render : function()
{
this.$el.html(this.template({
pfx: this.pfx,
label: this.model.get('name'),
}));
this.$caret = this.$el.find('#' + this.pfx + 'caret');
this.renderProperties();
this.$el.attr('class', this.pfx + 'sector no-select');
this.updateOpen();
return this;
},
if(objs){
var view = new PropertiesView({
collection: objs,
target: this.target,
propTarget: this.propTarget,
config: this.config,
});
this.$el.append(view.render().el);
}
},
});
renderProperties: function()
{
var objs = this.model.get('properties');
if(objs){
var view = new PropertiesView({
collection: objs,
target: this.target,
propTarget: this.propTarget,
config: this.config,
});
this.$el.append(view.render().el);
}
},
});
});

Loading…
Cancel
Save