2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
var Widget = require('./widget');
|
|
|
|
var Assistant = require('./assistant');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2018-05-16 09:36:42 +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-16 09:36:42 +00:00
|
|
|
},
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
_assistant: null,
|
|
|
|
_stepIndex: -1,
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
render: function() {
|
|
|
|
var bar = this.createRoot('div');
|
2015-07-03 05:49:45 +00:00
|
|
|
bar.className = 'htk-assistant-bar';
|
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
var previousButton = this.createElement('img');
|
2016-09-26 09:28:47 +00:00
|
|
|
previousButton.src = 'image/icon/light/go-previous.svg';
|
2015-07-03 05:49:45 +00:00
|
|
|
previousButton.className = 'previous';
|
|
|
|
previousButton.title = _('Previous');
|
2018-05-16 09:36:42 +00:00
|
|
|
previousButton.addEventListener('click', this.movePrevious.bind(this));
|
|
|
|
bar.appendChild(previousButton);
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
var steps = this.createElement('div');
|
|
|
|
bar.appendChild(steps);
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
var nextButton = this.createElement('img');
|
2016-09-26 09:28:47 +00:00
|
|
|
nextButton.src = 'image/icon/light/go-next.svg';
|
2015-07-03 05:49:45 +00:00
|
|
|
nextButton.className = 'next';
|
|
|
|
nextButton.title = _('Next');
|
2018-05-16 09:36:42 +00:00
|
|
|
nextButton.addEventListener('click', this.moveNext.bind(this));
|
|
|
|
bar.appendChild(nextButton);
|
2015-07-03 05:49:45 +00:00
|
|
|
|
|
|
|
this._steps = steps;
|
|
|
|
this._previousButton = previousButton;
|
|
|
|
this._nextButton = nextButton;
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
movePrevious: function() {
|
2015-07-03 05:49:45 +00:00
|
|
|
if (this._assistant)
|
2018-05-16 09:36:42 +00:00
|
|
|
this._assistant.movePrevious();
|
|
|
|
},
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
moveNext: function() {
|
2015-07-03 05:49:45 +00:00
|
|
|
if (this._assistant)
|
2018-05-16 09:36:42 +00:00
|
|
|
this._assistant.moveNext();
|
|
|
|
},
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
setStep: function(stepIndex) {
|
2015-07-03 05:49:45 +00:00
|
|
|
if (this._assistant)
|
2018-05-16 09:36:42 +00:00
|
|
|
this._assistant.setStep(stepIndex);
|
|
|
|
},
|
2015-07-03 05:49:45 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
onStepsChange: function() {
|
|
|
|
var stepCount = this._assistant.stepCount;
|
|
|
|
var steps = this._steps;
|
|
|
|
|
|
|
|
Vn.Node.removeChilds(steps);
|
|
|
|
steps.style.width = (stepCount * 1.7) + 'em';
|
|
|
|
|
|
|
|
for (var i = 0; i < stepCount; i++) {
|
|
|
|
var img = this.createElement('img');
|
|
|
|
img.src = 'image/step.svg';
|
|
|
|
img.addEventListener('click', this.setStep.bind(this, i));
|
|
|
|
steps.appendChild(img);
|
2015-07-03 05:49:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:36:42 +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;
|
|
|
|
|
2015-07-03 05:49:45 +00:00
|
|
|
if (this._stepIndex != -1)
|
2018-05-16 09:36:42 +00:00
|
|
|
childs[this._stepIndex].src = 'image/step.svg';
|
|
|
|
|
|
|
|
if (stepIndex >= stepCount)
|
|
|
|
return;
|
|
|
|
|
2015-07-03 05:49:45 +00:00
|
|
|
this._stepIndex = stepIndex;
|
|
|
|
|
|
|
|
if (stepIndex != -1)
|
2018-05-16 09:36:42 +00:00
|
|
|
childs[stepIndex].src = 'image/step-cur.svg';
|
2015-07-03 05:49:45 +00:00
|
|
|
|
|
|
|
var visibility = stepIndex <= 0 ? 'hidden' : 'visible';
|
|
|
|
this._previousButton.style.visibility = visibility;
|
|
|
|
|
|
|
|
var visibility = stepIndex >= stepCount - 1 ? 'hidden' : 'visible';
|
|
|
|
this._nextButton.style.visibility = visibility;
|
|
|
|
}
|
|
|
|
});
|