hedera-web/js/htk/assistant-bar/index.js

142 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-06-06 08:53:59 +00:00
require('./style.scss');
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';
2022-05-21 21:31:56 +00:00
var previousButton = new Htk.Button({
icon: 'arrow_back_ios',
tip: 'Previous'
}).node;
previousButton.classList.add('previous');
previousButton.addEventListener('click', this.movePrevious.bind(this));
bar.appendChild(previousButton);
2015-07-03 05:49:45 +00:00
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
2022-05-21 21:31:56 +00:00
var nextButton = new Htk.Button({
icon: 'arrow_forward_ios',
tip: 'Next'
}).node;
nextButton.classList.add('next');
nextButton.addEventListener('click', this.moveNext.bind(this));
bar.appendChild(nextButton);
2015-07-03 05:49:45 +00:00
2022-05-21 21:31:56 +00:00
var endButton = new Htk.Button({
icon: 'done',
tip: 'Confirm'
}).node;
endButton.classList.add('end');
2018-05-17 08:52:27 +00:00
endButton.addEventListener('click', this.end.bind(this));
bar.appendChild(endButton);
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
}
});