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

141 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-06-06 08:53:59 +00:00
require('./style.scss');
2022-06-06 12:49:18 +00:00
var Component = require('vn/component');
2022-06-06 08:53:59 +00:00
var Assistant = require('../assistant');
2016-09-26 09:28:47 +00:00
module.exports = new Class({
2022-06-06 12:49:18 +00:00
Extends: Component,
Tag: 'htk-assistant-bar',
Properties: {
assistant: {
type: Assistant,
2022-11-16 01:46:44 +00:00
set(x) {
this.link({_assistant: x}, {
'step-change': this.onStepChange,
'steps-change': this.onStepsChange
});
this.onStepsChange();
},
2022-11-16 01:46:44 +00:00
get() {
2015-07-03 05:49:45 +00:00
return this._assistant;
}
2018-05-17 08:52:27 +00:00
},
disabled: {
type: Boolean,
2022-11-16 01:46:44 +00:00
set(x) {
2018-05-17 08:52:27 +00:00
this._disabled = x;
this._previousButton.disabled = x;
this._nextButton.disabled = x;
this._endButton.disabled = x;
},
2022-11-16 01:46:44 +00:00
get() {
2018-05-17 08:52:27 +00:00
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
2022-11-16 01:46:44 +00:00
render() {
2022-06-06 17:13:57 +00:00
var node = this.createRoot('div');
2022-05-21 21:31:56 +00:00
var previousButton = new Htk.Button({
icon: 'arrow_back',
2022-05-21 21:31:56 +00:00
tip: 'Previous'
}).node;
previousButton.classList.add('previous');
previousButton.addEventListener('click', this.movePrevious.bind(this));
2022-06-06 17:13:57 +00:00
node.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';
2022-06-06 17:13:57 +00:00
node.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',
2022-05-21 21:31:56 +00:00
tip: 'Next'
}).node;
nextButton.classList.add('next');
nextButton.addEventListener('click', this.moveNext.bind(this));
2022-06-06 17:13:57 +00:00
node.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));
2022-06-06 17:13:57 +00:00
node.appendChild(endButton);
2018-05-17 08:52:27 +00:00
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
2022-11-16 01:46:44 +00:00
movePrevious() {
2015-07-03 05:49:45 +00:00
if (this._assistant)
this._assistant.movePrevious();
},
2015-07-03 05:49:45 +00:00
2022-11-16 01:46:44 +00:00
moveNext() {
2015-07-03 05:49:45 +00:00
if (this._assistant)
this._assistant.moveNext();
},
2015-07-03 05:49:45 +00:00
2022-11-16 01:46:44 +00:00
end() {
2018-05-17 08:52:27 +00:00
if (this._assistant)
this._assistant.end();
},
2022-11-16 01:46:44 +00:00
setStep(stepIndex) {
2015-07-03 05:49:45 +00:00
if (this._assistant)
this._assistant.setStep(stepIndex);
},
2015-07-03 05:49:45 +00:00
2022-11-16 01:46:44 +00:00
onStepsChange() {
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();
},
2022-11-16 01:46:44 +00:00
onStepChange() {
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
}
});