0
1
Fork 0
hedera-web-mindshore/js/htk/assistant-bar.js

148 lines
3.5 KiB
JavaScript
Raw Normal View History

2015-07-03 05:49:45 +00:00
var Widget = require('./widget');
var Assistant = require('./assistant');
2016-09-26 09:28:47 +00:00
module.exports = new Class({
Extends: Widget,
Tag: 'htk-assistant-bar',
Properties: {
assistant: {
type: Assistant,
set: function(x) {
this.link({_assistant: x}, {
'step-change': this.onStepChange,
'steps-change': this.onStepsChange
});
this.onStepsChange();
},
get: function() {
2015-07-03 05:49:45 +00:00
return this._assistant;
}
2018-05-17 08:52:27 +00:00
},
disabled: {
type: Boolean,
set: function(x) {
this._disabled = x;
this._previousButton.disabled = x;
this._nextButton.disabled = x;
this._endButton.disabled = x;
},
get: function() {
return this._disabled;
}
2015-07-03 05:49:45 +00:00
}
},
2015-07-03 05:49:45 +00:00
_assistant: null,
_stepIndex: -1,
2018-05-17 08:52:27 +00:00
_disabled: false,
2015-07-03 05:49:45 +00:00
render: function() {
var bar = this.createRoot('div');
2015-07-03 05:49:45 +00:00
bar.className = 'htk-assistant-bar';
2018-05-17 08:52:27 +00:00
var previousButton = this.createElement('button');
2015-07-03 05:49:45 +00:00
previousButton.className = 'previous';
previousButton.title = _('Previous');
previousButton.addEventListener('click', this.movePrevious.bind(this));
bar.appendChild(previousButton);
2015-07-03 05:49:45 +00:00
2018-05-17 08:52:27 +00:00
var img = this.createElement('img');
img.src = 'image/icon/light/go-previous.svg';
previousButton.appendChild(img);
var steps = this.createElement('div');
2018-05-17 08:52:27 +00:00
steps.className = 'steps';
bar.appendChild(steps);
2015-07-03 05:49:45 +00:00
2018-05-17 08:52:27 +00:00
var nextButton = this.createElement('button');
2015-07-03 05:49:45 +00:00
nextButton.className = 'next';
nextButton.title = _('Next');
nextButton.addEventListener('click', this.moveNext.bind(this));
bar.appendChild(nextButton);
2015-07-03 05:49:45 +00:00
2018-05-17 08:52:27 +00:00
var img = this.createElement('img');
img.src = 'image/icon/light/go-next.svg';
nextButton.appendChild(img);
var endButton = this.createElement('button');
endButton.className = 'end';
endButton.title = _('Confirm');
endButton.addEventListener('click', this.end.bind(this));
bar.appendChild(endButton);
var img = this.createElement('img');
img.src = 'image/icon/light/ok.svg';
endButton.appendChild(img);
2015-07-03 05:49:45 +00:00
this._steps = steps;
this._previousButton = previousButton;
this._nextButton = nextButton;
2018-05-17 08:52:27 +00:00
this._endButton = endButton;
},
2015-07-03 05:49:45 +00:00
movePrevious: function() {
2015-07-03 05:49:45 +00:00
if (this._assistant)
this._assistant.movePrevious();
},
2015-07-03 05:49:45 +00:00
moveNext: function() {
2015-07-03 05:49:45 +00:00
if (this._assistant)
this._assistant.moveNext();
},
2015-07-03 05:49:45 +00:00
2018-05-17 08:52:27 +00:00
end: function() {
if (this._assistant)
this._assistant.end();
},
setStep: function(stepIndex) {
2015-07-03 05:49:45 +00:00
if (this._assistant)
this._assistant.setStep(stepIndex);
},
2015-07-03 05:49:45 +00:00
onStepsChange: function() {
var stepCount = this._assistant.stepCount;
var steps = this._steps;
Vn.Node.removeChilds(steps);
for (var i = 0; i < stepCount; i++) {
2018-05-17 08:52:27 +00:00
var img = this.createElement('div');
img.src = 'image/step.svg';
img.addEventListener('click', this.setStep.bind(this, i));
steps.appendChild(img);
2015-07-03 05:49:45 +00:00
}
this.onStepChange();
},
onStepChange: function() {
var childs = this._steps.childNodes;
var stepCount = childs ? childs.length : 0;
var stepIndex = this._assistant ? this._assistant.step : -1;
2018-05-17 08:52:27 +00:00
if (this._stepIndex != -1) {
childs[this._stepIndex].src = 'image/step.svg';
2018-05-17 08:52:27 +00:00
childs[this._stepIndex].className = '';
}
if (stepIndex >= stepCount)
return;
2015-07-03 05:49:45 +00:00
this._stepIndex = stepIndex;
2018-05-17 08:52:27 +00:00
if (stepIndex != -1) {
childs[stepIndex].src = 'image/step-cur.svg';
2018-05-17 08:52:27 +00:00
childs[this._stepIndex].className = 'selected';
}
2015-07-03 05:49:45 +00:00
2018-05-17 08:52:27 +00:00
var visibility = stepIndex > 0 ? 'visible' : 'hidden';
2015-07-03 05:49:45 +00:00
this._previousButton.style.visibility = visibility;
2018-05-17 08:52:27 +00:00
var isEnd = stepIndex >= stepCount - 1;
this._nextButton.style.display = isEnd ? 'none' : 'block';
this._endButton.style.display = isEnd ? 'block' : 'none';
2015-07-03 05:49:45 +00:00
}
});