acha-framework
Version:
is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...
111 lines • 3.84 kB
JavaScript
(function ($, angular, underscore, window, document, undefined) {
'use strict';
angular.module('frontend.directives').run([
'$rootScope',
function ($rootScope) {
Object.defineProperty($rootScope, '$WizardContext', {
get: function () {
return this.$parent;
}
});
}
]).directive('wizard', [
'$compile',
'$templateCache',
function ($compile, $templateCache) {
return {
restrict: 'E',
replace: true,
scope: {
tag: '<?',
disabled: '=?',
visible: '=?',
cssClass: '=?',
nextText: '<?',
nextTextTranslate: '=?',
backText: '<?',
backTextTranslate: '=?',
keepScope: '=?',
position: '=?',
onChanged: '<?',
onEnter: '<?',
onExit: '<?',
steps: '=?',
model: '=?'
},
compile: function ($$element) {
var content = $$element.html();
$$element.empty();
var templateUrl = '/templates/framework/directives/wizard/template.html';
var template = $templateCache.get(templateUrl);
var $template = $(template);
$template.find('tabs').html(content);
return {
pre: function (scope, element, attr) {
scope.vm = { currentIndex: 0 };
scope.vm.onNext = function () {
var index = scope.steps.indexOf(scope.model);
var target = index + 1;
if (target === scope.steps.length)
return;
if (scope.vm.triggerPick) {
scope.vm.triggerPick(scope.steps[target]);
}
};
scope.vm.onBack = function () {
var index = scope.steps.indexOf(scope.model);
var target = index - 1;
if (target === -1)
return;
if (scope.vm.triggerPick) {
scope.vm.triggerPick(scope.steps[target]);
}
};
scope.vm.init = function () {
if (angular.isUndefined(scope.disabled)) {
scope.disabled = false;
}
if (angular.isUndefined(scope.visible)) {
scope.visible = true;
}
if (angular.isUndefined(scope.cssClass)) {
scope.cssClass = '';
}
if (angular.isUndefined(scope.nextTextTranslate)) {
scope.nextTextTranslate = 'general.next';
}
if (angular.isUndefined(scope.backTextTranslate)) {
scope.backTextTranslate = 'general.previous';
}
scope.vm.compile();
scope.vm.bind();
};
scope.vm.compile = function () {
element.append($template);
$compile($template)(scope);
};
scope.vm.bind = function () {
Object.defineProperty(scope.vm, 'nextDisabled', {
get: function () {
return scope.vm.currentIndex === scope.steps.length - 1;
}
});
Object.defineProperty(scope.vm, 'backDisabled', {
get: function () {
return scope.vm.currentIndex === 0;
}
});
scope.$watch('model', function (val, old) {
if (angular.isUndefined(val))
return;
scope.vm.currentIndex = scope.steps.indexOf(val);
});
};
scope.vm.init();
}
};
}
};
}
]);
}(jQuery, angular, _, window, document));