forked from gongfudev/Exquis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolPanel.js
90 lines (83 loc) · 3.16 KB
/
controlPanel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
define(['csshelper', 'tabs', 'ui', 'paramController' ], function(csshelper, tabConstructor, ui, paramController){
const TAB_NAME_EDITOR = 'Editor';
var rootDom = document.getElementById('control-panel'),
editorController,
theCell,
store,
tabs = tabConstructor({tabsRoot: 'control-panel', tabs:[
{name: "Animations",
initHandler: null,
clickHandler: function(activeContentDiv){
var chooseAnimation = makeChooseAnimation(theCell.canvasAnim, store);
chooseAnimation(activeContentDiv);
}},
{name: TAB_NAME_EDITOR,
initHandler: null,
clickHandler: async function(activeContentDiv){
try{
if (editorController) {
await editorController.updateWithCanvasAnim(
theCell.canvasAnim, activeContentDiv.id)
}
} catch (e) {
console.error(e);
}
}},
{name: "Parameters",
initHandler: null,
clickHandler: function(activeContentDiv){
paramController.refreshController(activeContentDiv, theCell, editorController);
}}
]});
var show = async function(cell){
theCell = cell;
//TODO create editor view if we have an editorController:
// For this we need the parentId of the editor for source.lang
let editorViewPromise = Promise.resolve(true);
if(editorController){
const parentId = tabs.getParentDiv(TAB_NAME_EDITOR).id;
editorViewPromise = theCell
.canvasAnim
.getSourceCode()
.then(function(source){
// console.log('lang', source.lang);
return editorController.provideViewForLang(source.lang, parentId);
});
}
await editorViewPromise.then();
csshelper.removeClass(rootDom, 'invisible');
tabs.refreshActiveTab();
};
var hide = function(){
csshelper.addClass(rootDom, 'invisible');
};
var addEditor = function(zeEditorController){
editorController = zeEditorController;
};
//TODO use this in animation tab
var makeChooseAnimation = function(canvasAnim, store){
var loadAnimation = function(animationName){
if (!animationName){
return;
}
var fileUri = store.animationNameToUri(animationName);
canvasAnim.loadAnim(fileUri);
};
var chooseAnimation = function(parent){
store.loadAnimationList().then(function(fileUris){
var names = fileUris.map(store.uriToAnimationName);
ui.createList(parent, names, loadAnimation, canvasAnim.animationName);
});
};
return chooseAnimation;
};
var makeControlPanel = function(zeStore){
store = zeStore;
return {
hide: hide,
show: show,
addEditor: addEditor
};
};
return makeControlPanel;
});