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

118 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-07-03 05:49:45 +00:00
2016-09-26 09:28:47 +00:00
var Widget = require ('./widget');
var Assistant = require ('./assistant');
module.exports = new Class
2015-07-03 05:49:45 +00:00
({
2016-09-26 09:28:47 +00:00
Extends: Widget
2015-07-03 05:49:45 +00:00
,Tag: 'htk-assistant-bar'
,Properties:
{
assistant:
{
2016-09-26 09:28:47 +00:00
type: Assistant
2015-07-03 05:49:45 +00:00
,set: function (x)
{
this.link ({_assistant: x}, {'step-change': this.onStepChange});
var stepCount = x.stepCount;
var steps = this._steps;
Vn.Node.removeChilds (steps);
steps.style.width = (stepCount * 1.7) + 'em';
for (var i = 0; i < stepCount; i++)
{
2016-10-16 14:16:08 +00:00
var img = this.createElement ('img');
2015-07-03 05:49:45 +00:00
img.src = 'image/step.svg';
img.addEventListener ('click', this.setStep.bind (this, i));
steps.appendChild (img);
}
this.onStepChange ();
}
,get: function ()
{
return this._assistant;
}
}
}
,_assistant: null
,_stepIndex: -1
2016-10-16 14:16:08 +00:00
,render: function ()
2015-07-03 05:49:45 +00:00
{
2016-10-16 14:16:08 +00:00
var bar = this.createRoot ('div');
2015-07-03 05:49:45 +00:00
bar.className = 'htk-assistant-bar';
2016-10-16 14:16:08 +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');
previousButton.addEventListener ('click', this.movePrevious.bind (this));
bar.appendChild (previousButton);
2016-10-16 14:16:08 +00:00
var steps = this.createElement ('div');
2015-07-03 05:49:45 +00:00
bar.appendChild (steps);
2016-10-16 14:16:08 +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');
nextButton.addEventListener ('click', this.moveNext.bind (this));
bar.appendChild (nextButton);
this._steps = steps;
this._previousButton = previousButton;
this._nextButton = nextButton;
}
,movePrevious: function ()
{
if (this._assistant)
this._assistant.movePrevious ();
}
,moveNext: function ()
{
if (this._assistant)
this._assistant.moveNext ();
}
,setStep: function (stepIndex)
{
if (this._assistant)
this._assistant.setStep (stepIndex);
}
,onStepChange: function ()
{
if (this._assistant)
{
var stepIndex = this._assistant.step;
var stepCount = this._assistant.stepCount;
}
else
{
var stepIndex = -1;
var stepCount = 0;
}
if (this._stepIndex != -1)
this._steps.childNodes[this._stepIndex].src = 'image/step.svg';
this._stepIndex = stepIndex;
if (stepIndex != -1)
this._steps.childNodes[stepIndex].src = 'image/step-cur.svg';
var visibility = stepIndex <= 0 ? 'hidden' : 'visible';
this._previousButton.style.visibility = visibility;
var visibility = stepIndex >= stepCount - 1 ? 'hidden' : 'visible';
this._nextButton.style.visibility = visibility;
}
});