|
|
|
@ -25,36 +25,30 @@ |
|
|
|
* |
|
|
|
* @module Panels |
|
|
|
*/ |
|
|
|
import { Module } from '../abstract'; |
|
|
|
import EditorModel from '../editor/model/Editor'; |
|
|
|
import defaults from './config/config'; |
|
|
|
import Panel from './model/Panel'; |
|
|
|
import Panels from './model/Panels'; |
|
|
|
import PanelsView from './view/PanelsView'; |
|
|
|
|
|
|
|
export default class PanelsManager { |
|
|
|
/** |
|
|
|
* Name of the module |
|
|
|
* @type {String} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
name = 'Panels'; |
|
|
|
|
|
|
|
config = {}; |
|
|
|
export default class PanelsManager extends Module<typeof defaults> { |
|
|
|
//config = {};
|
|
|
|
panels: Panels; |
|
|
|
PanelsViewObj?: PanelsView; |
|
|
|
|
|
|
|
/** |
|
|
|
* Initialize module. Automatically called with a new instance of the editor |
|
|
|
* @param {Object} config Configurations |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
init(config) { |
|
|
|
this.config = config || {}; |
|
|
|
constructor(em: EditorModel) { |
|
|
|
super(em, 'Panels', defaults); |
|
|
|
this.panels = new Panels(this.config.defaults); |
|
|
|
for (var name in defaults) { |
|
|
|
//@ts-ignore
|
|
|
|
if (!(name in this.config)) this.config[name] = defaults[name]; |
|
|
|
} |
|
|
|
|
|
|
|
var ppfx = this.config.pStylePrefix; |
|
|
|
if (ppfx) this.config.stylePrefix = ppfx + this.config.stylePrefix; |
|
|
|
|
|
|
|
this.panels = new Panels(this.config.defaults); |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
@ -85,7 +79,7 @@ export default class PanelsManager { |
|
|
|
* buttons : [...], |
|
|
|
* }); |
|
|
|
*/ |
|
|
|
addPanel(panel) { |
|
|
|
addPanel(panel: Panel) { |
|
|
|
return this.panels.add(panel); |
|
|
|
} |
|
|
|
|
|
|
|
@ -103,7 +97,7 @@ export default class PanelsManager { |
|
|
|
* const newPanel = panelManager.removePanel('myNewPanel'); |
|
|
|
* |
|
|
|
*/ |
|
|
|
removePanel(panel) { |
|
|
|
removePanel(panel: Panel) { |
|
|
|
return this.panels.remove(panel); |
|
|
|
} |
|
|
|
|
|
|
|
@ -114,7 +108,7 @@ export default class PanelsManager { |
|
|
|
* @example |
|
|
|
* var myPanel = panelManager.getPanel('myNewPanel'); |
|
|
|
*/ |
|
|
|
getPanel(id) { |
|
|
|
getPanel(id: string) { |
|
|
|
var res = this.panels.where({ id }); |
|
|
|
return res.length ? res[0] : null; |
|
|
|
} |
|
|
|
@ -149,7 +143,7 @@ export default class PanelsManager { |
|
|
|
* ... |
|
|
|
* } |
|
|
|
*/ |
|
|
|
addButton(panelId, button) { |
|
|
|
addButton(panelId: string, button: any) { |
|
|
|
var pn = this.getPanel(panelId); |
|
|
|
return pn ? pn.get('buttons').add(button) : null; |
|
|
|
} |
|
|
|
@ -171,7 +165,7 @@ export default class PanelsManager { |
|
|
|
* const removedButton = panelManager.removeButton('myNewPanel', 'myNewButton'); |
|
|
|
* |
|
|
|
*/ |
|
|
|
removeButton(panelId, button) { |
|
|
|
removeButton(panelId: string, button: any) { |
|
|
|
var pn = this.getPanel(panelId); |
|
|
|
return pn && pn.get('buttons').remove(button); |
|
|
|
} |
|
|
|
@ -184,7 +178,7 @@ export default class PanelsManager { |
|
|
|
* @example |
|
|
|
* var button = panelManager.getButton('myPanel','myButton'); |
|
|
|
*/ |
|
|
|
getButton(panelId, id) { |
|
|
|
getButton(panelId: string, id: string) { |
|
|
|
var pn = this.getPanel(panelId); |
|
|
|
if (pn) { |
|
|
|
var res = pn.get('buttons').where({ id }); |
|
|
|
@ -202,6 +196,7 @@ export default class PanelsManager { |
|
|
|
this.PanelsViewObj && this.PanelsViewObj.remove(); |
|
|
|
this.PanelsViewObj = new PanelsView({ |
|
|
|
collection: this.panels, |
|
|
|
//@ts-ignore
|
|
|
|
config: this.config, |
|
|
|
}); |
|
|
|
return this.PanelsViewObj.render().el; |
|
|
|
@ -213,6 +208,7 @@ export default class PanelsManager { |
|
|
|
*/ |
|
|
|
active() { |
|
|
|
this.getPanels().each(p => { |
|
|
|
//@ts-ignore
|
|
|
|
p.get('buttons').each(btn => { |
|
|
|
btn.get('active') && btn.trigger('updateActive'); |
|
|
|
}); |
|
|
|
@ -225,6 +221,7 @@ export default class PanelsManager { |
|
|
|
*/ |
|
|
|
disableButtons() { |
|
|
|
this.getPanels().each(p => { |
|
|
|
//@ts-ignore
|
|
|
|
p.get('buttons').each(btn => { |
|
|
|
if (btn.get('disable')) btn.trigger('change:disable'); |
|
|
|
}); |
|
|
|
@ -235,6 +232,5 @@ export default class PanelsManager { |
|
|
|
this.panels.reset(); |
|
|
|
this.panels.stopListening(); |
|
|
|
this.PanelsViewObj && this.PanelsViewObj.remove(); |
|
|
|
[this.config, this.panels, this.PanelsViewObj].forEach(i => (i = {})); |
|
|
|
} |
|
|
|
} |