--- /dev/null
+(function() {
+ "use strict";
+
+ angular.module("nero.app.dashboard")
+ .directive("schoollifeheader", schoollifeheaderDirective);
+
+ function schoollifeheaderDirective() {
+ return {
+ restrict: "E",
+ scope: {
+ isHeadMaster: "="
+ },
+ templateUrl: contextPath + "/js/schoollife/schoollifeheader.html?t="+dashboardTimestamp,
+ controller: SchoollifeheaderController,
+ controllerAs: "SchoollifeheaderCtrl",
+ bindToController:true
+ };
+ }
+
+ SchoollifeheaderController.$inject = ["$uibModal", "schoollifeService", "$rootScope", "toastr"];
+
+ function SchoollifeheaderController($uibModal, schoollifeService, $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) {
+
+ console.log("get children for parentUserId "+userId);
+
+ schoollifeService.getChildren(userId)
+ .then(function(data) {
+ toastr.success(data.message);
+ vm.childrenList = data.childrenList;
+ })
+ ["catch"](function(message){
+ toastr.error(message);
+ });
+ }
+
+
+ // Broadcast selectedChild
+ function childSelected() {
+ console.log("child selected");
+ console.log(selectedChild);
+ $rootScope.$broadcast('select-child', {childId: selectedChild.childId});
+ }
+
+ function init() {
+ schoollifeService.getUserInfos()
+ .then(function(data) {
+ vm.userId = data.userId;
+ console.log("current userId is "+vm.userId);
+ vm.isTeacher = data.isTeacher;
+ vm.isStudent = data.isStudent;
+ vm.isParent = data.isParent;
+ if (vm.isParent) {
+ console.log("user is parent");
+ 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);
+ });
+ }
+
+ }
+})();