--- /dev/null
+(function() {
+ "use strict";
+
+ angular.module("nero.app.dashboard")
+ .directive("schedulerheader", schedulerheaderDirective);
+
+ function schedulerheaderDirective() {
+ return {
+ restrict: "E",
+ scope: {
+ isHeadMaster: "="
+ },
+ templateUrl: contextPath + "/js/scheduler/schedulerheader.html?t="+dashboardTimestamp,
+ controller: SchedulerheaderController,
+ controllerAs: "SchedulerheaderCtrl",
+ bindToController:true
+ };
+ }
+
+ SchedulerheaderController.$inject = ["$uibModal", "schedulerService", "$rootScope", "toastr"];
+
+ function SchedulerheaderController($uibModal, schedulerService, $rootScope, toastr) {
+ var vm = this;
+
+ vm.userId;
+ vm.isStudent;
+ vm.isParent;
+ vm.isTeacher;
+
+ vm.childrenList = [];
+ vm.children = [];
+ vm.selectedChild;
+ vm.moreThanOneChild = false;
+
+ // functions
+ vm.getChildren = getChildren;
+ vm.childSelected = childSelected;
+ vm.init = init;
+
+ //init();
+
+ function getChildren(userId) {
+
+ schedulerService.getChildren(userId)
+ .then(function(data) {
+ toastr.success(data.message);
+ vm.childrenList = data.childrenList;
+ })
+ ["catch"](function(message){
+ toastr.error(message);
+ });
+ }
+
+
+ // Broadcast selectedChild
+ function childSelected() {
+ $rootScope.$broadcast('select-child', {childId: selectedChild.childId});
+ }
+
+ function init() {
+ schedulerService.getUserInfos()
+ .then(function(data) {
+ vm.userId = data.userId;
+ vm.isTeacher = data.isTeacher;
+ vm.isStudent = data.isStudent;
+ vm.isParent = data.isParent;
+ if (vm.isParent) {
+ getChildren(vm.userId);
+
+ // Build children list
+ vm.children = [];
+ for (var i = 0 ; i < vm.childrenList.length ; i++) {
+ var child = vm.childrenList[i];
+ vm.children.push(child.childFirstName + " " + child.childLastName);
+ }
+
+ // Default child is the first one
+ if (vm.childrenList.length > 0) {
+ vm.selectedChild = vm.childrenList[0];
+ if (vm.childrenList.length > 1) {
+ vm.moreThanOneChild = true;
+ }
+ }
+ }
+ })
+ ["catch"](function(message){
+ toastr.error(message);
+ });
+ }
+
+ }
+})();