Browse Source

Update Panel with comments

pull/36/head
Artur Arseniev 11 years ago
parent
commit
486e71df93
  1. 126
      src/panels/main.js

126
src/panels/main.js

@ -2,51 +2,93 @@ define(function(require) {
/** /**
* @class Panel * @class Panel
* @param {Object} Configurations * @param {Object} Configurations
* *
* @return {Object} * @return {Object}
* */ * */
function Panel(config) function Panel(config){
{ var c = config || {},
var c = config || {}, defaults = require('./config/config'),
defaults = require('./config/config'), Panels = require('./model/Panels'),
Panels = require('./model/Panels'), PanelsView = require('./view/PanelsView');
PanelsView = require('./view/PanelsView');
// Set default options // Set default options
for (var name in defaults) { for (var name in defaults) {
if (!(name in c)) if (!(name in c))
c[name] = defaults[name]; c[name] = defaults[name];
} }
this.panels = new Panels(c.defaults); var panels = new Panels(c.defaults);
var obj = { var obj = {
collection : this.panels, collection : panels,
config : c, config : c,
}; };
this.PanelsView = new PanelsView(obj); var PanelsViewObj = new PanelsView(obj);
}
return {
Panel.prototype = {
/**
getPanels : function(){ * Returns the collection of panels
return this.panels; * @return {Collection} Collection of panel
*/
getPanels: function(){
return panels;
}, },
addPanel : function(obj){ /**
return this.panels.add(obj); * Add new panel to the collection
* @param {Object|Panel} panel Object with right properties or an instance of Panel
* @return {Panel} Added panel. Useful in case of passed argument was an Object
* @example
* var newPanel = panelService.addPanel({
* id: 'myNewPanel',
* visible : true,
* buttons : [...],
* });
*/
addPanel: function(panel){
return panels.add(panel);
}, },
/**
* Get panel by ID
* @param {string} id Id string
* @return {Panel|null}
* @example
* var myPanel = panelService.getPanel('myNewPanel');
*/
getPanel : function(id){ getPanel : function(id){
var res = this.panels.where({id: id}); var res = panels.where({id: id});
return res.length ? res[0] : null; return res.length ? res[0] : null;
}, },
addButton : function(panelId, obj){ /**
* Add button to the panel
* @param {string} panelId Panel's ID
* @param {Object|Button} button Button object or instance of Button
* @return {Button|null} Added button. Useful in case of passed button was an Object
* @example
* var newButton = panelService.addButton('myNewPanel',{
* id: 'myNewButton',
* className: 'someClass',
* command: 'someCommand',
* attributes: { title: 'Some title'},
* active: false,
* });
*/
addButton : function(panelId, button){
var pn = this.getPanel(panelId); var pn = this.getPanel(panelId);
return pn ? pn.get('buttons').add(obj) : null; return pn ? pn.get('buttons').add(button) : null;
}, },
/**
* Get button from the panel
* @param {string} panelId Panel's ID
* @param {string} id Button's ID
* @return {Button|null}
* @example
* var button = panelService.getButton('myPanel','myButton');
*/
getButton : function(panelId, id){ getButton : function(panelId, id){
var pn = this.getPanel(panelId); var pn = this.getPanel(panelId);
if(pn){ if(pn){
@ -55,7 +97,19 @@ define(function(require) {
} }
return null; return null;
}, },
/**
* Render panels and buttons
* @return {HTMLElement}
*/
render : function(){
return PanelsViewObj.render().el;
},
/**
* Active activable buttons
* @private
*/
active : function(){ active : function(){
this.getPanels().each(function(p){ this.getPanels().each(function(p){
p.get('buttons').each(function(btn){ p.get('buttons').each(function(btn){
@ -64,11 +118,9 @@ define(function(require) {
}); });
}); });
}, },
render : function(){ };
return this.PanelsView.render().el; }
},
};
return Panel; return Panel;
}); });
Loading…
Cancel
Save