hedera-web/js/htk/assistant.js

147 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-07-03 05:49:45 +00:00
2017-10-28 15:13:00 +00:00
var Step = require ('./step');
2016-09-26 09:28:47 +00:00
module.exports = new Class
2015-07-03 05:49:45 +00:00
({
2017-10-28 15:13:00 +00:00
Extends: Vn.Component
2015-07-03 05:49:45 +00:00
,Tag: 'htk-assistant'
,Properties:
{
stepCount:
{
type: Number
,set: function (x)
{
this._stepCount = x;
if (x > 0)
this.setStep (0);
else
this.setStep (-1);
}
,get: function ()
{
return this._stepCount;
}
},
step:
{
type: Number
,set: function (x)
{
this.setStep (x);
}
,get: function ()
{
return this._stepIndex;
}
},
stepFunc:
{
type: Function
,set: function (x)
{
this._stepFunc = x;
this.setStep (this._stepIndex);
}
,get: function ()
{
return this._stepFunc;
}
},
node:
{
type: Object
,set: function (x)
{
x.className = 'htk-assistant';
}
},
}
2017-10-28 15:13:00 +00:00
,_steps: []
2015-07-03 05:49:45 +00:00
,_stepNode: null
,_stepIndex: -1
2017-10-28 15:13:00 +00:00
,_stepName: null
2015-07-03 05:49:45 +00:00
,_stepCount: 0
,_stepFunc: null
2017-10-28 15:13:00 +00:00
,appendChild: function (step)
{
if (!(step instanceof Step))
return;
this._node.appendChild (step.node);
this._steps[step.name] = step;
if (step.name === this._stepName)
this._showStepNode ();
}
,render: function ()
{
var node = this.createRoot ('div');
node.className = 'htk-assistant';
}
2015-07-03 05:49:45 +00:00
,setStep: function (stepIndex)
{
if (!(stepIndex >= -1 && stepIndex < this.stepCount))
return;
if (this._stepFunc && stepIndex != -1)
{
2017-10-28 15:13:00 +00:00
var stepName = this._stepFunc (stepIndex);
2015-07-03 05:49:45 +00:00
2017-10-28 15:13:00 +00:00
if (stepName)
2015-07-03 05:49:45 +00:00
{
2017-10-28 15:13:00 +00:00
if (this._step)
this._step.node.style.display = 'none';
2015-07-03 05:49:45 +00:00
2017-10-28 15:13:00 +00:00
this._stepName = stepName;
this._showStepNode ()
2015-07-03 05:49:45 +00:00
this._setStepIndex (stepIndex);
}
else if (this._stepIndex < stepIndex)
this.setStep (stepIndex + 1);
else
this.setStep (stepIndex - 1);
}
else
2017-10-28 15:13:00 +00:00
{
if (this._step)
this._step.node.style.display = 'none';
this._stepName = null;
2015-07-03 05:49:45 +00:00
this._setStepIndex (stepIndex);
2017-10-28 15:13:00 +00:00
}
2015-07-03 05:49:45 +00:00
}
2017-10-28 15:13:00 +00:00
,_showStepNode: function ()
{
var step = this._steps[this._stepName];
if (step)
{
this._step = step;
step.node.style.display = 'block';
}
}
2015-07-03 05:49:45 +00:00
,_setStepIndex: function (stepIndex)
{
this._stepIndex = stepIndex;
2017-04-19 06:16:37 +00:00
this.emit ('step-change', stepIndex);
2015-07-03 05:49:45 +00:00
}
,movePrevious: function ()
{
this.setStep (this._stepIndex - 1);
}
,moveNext: function ()
{
this.setStep (this._stepIndex + 1);
}
});