app.directive('onFinishRender', function ($timeout) { return { restrict: 'A', link: function (scope, element, attr) { if (scope.$last === true) { $timeout(function () { scope.$emit('ngRepeatFinished'); }); } } } }); app.directive('scrollIf', function () { return function (scope, element, attributes) { setTimeout(function () { if (scope.$eval(attributes.scrollIf)) { window.scrollTo(0, element[0].offsetTop - 100) } }); } }); app.filter('trusted', ['$sce', function ($sce) { return $sce.trustAsResourceUrl; }]); app.filter('htmlToPlaintext', function() { return function(text) { return text ? String(text).replace(/<[^>]+>| /gm, '') : ''; }; }); app.directive('fileModel', ['$parse', function ($parse) { return { restrict: 'A', link: function(scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind('change', function(){ scope.$apply(function(){ modelSetter(scope, element[0].files[0]); }); }); } }; }]); app.filter('sce', ['$sce', function ($sce) { return $sce.trustAsHtml; }]); app.controller('listController',function($scope,SharedState,$location,notify,$window,$routeParams) { $scope.filter = {}; $scope.lorem = "adas";//SharedState.values(); $scope.focussed=""; $scope.selectTypeList = notify.selectTypeList; $scope.selectSortbyList = notify.selectSortbyList; $scope.selectStatusList = notify.selectStatusList; // alert($scope.selectStatusList); if("myFilter" in notify) var thisFilter= notify.myFilter; else var thisFilter={}; if("selectType" in thisFilter ) { $scope.selectType =thisFilter.selectType; } else $scope.selectType = $scope.selectTypeList[0]; $scope.selectDate = ["date1","date2"]; if("selectSortby" in thisFilter) { $scope.selectSortby =thisFilter.selectSortby; } else $scope.selectSortby = $scope.selectSortbyList[1]; if( "selectStatus" in thisFilter) { $scope.selectStatus =thisFilter.selectStatus; }else $scope.selectStatus=$scope.selectStatusList[0] $scope.comments = []; $scope.loadComments = function(){ var task_key = SharedState.get("myAccordion"); filter = {}; filter["filter[task_key]"] = task_key; notify.loadComments($scope,filter); } $scope.search=null; $scope.focusSearchbox=function(){ } $scope.loadFile = function(){ try { $location.path("/file"); } catch (ex) { console.log("caught " + ex); } } $scope.alertComment = {}; $scope.alertTask = {}; $scope.marginTop = function(index){ return {'margin-top': index*43+'px' } } $scope.showFile = function(comment){ $location.path("/file/"+comment.id); } $scope. listindex = 0; $scope.submitData = {}; $scope.submitTaskChange = function(submitData,task_key){ $scope.alertTask[task_key] = true; var file = document.querySelector("#fileComment-"+task_key).files[0]; var reader = new FileReader(); if(file){ reader.onload = function () { submitData.myFile =reader.result; }; reader.readAsDataURL(file); } console.log(task_key,submitData); if("text" in submitData && submitData.text.length>0){ if("myFile" in submitData){ if("base64" in submitData.myFile){ if ( submitData.myFile.base64 == null) { alert("File too large"); return ; } }else { alert("File too large"); return; } notify.sendTaskStatusChange(submitData,task_key); }else notify.sendTaskStatusChange(submitData,task_key); } else{ // $scope.alertBox = "לא ניתן לשלוח תגובה ריקה"; // $scope.alertComment[task_key] = true; notify.sendTaskStatusChange(submitData,task_key); console.log('submitTaskChange ' +task_key); } } $scope.fileChaged = function(sendComment,task_key){ var file = document.querySelector("#fileComment-"+task_key).files[0]; var reader = new FileReader(); if(file){ reader.onload = function () { sendComment.myFile =reader.result; }; reader.readAsDataURL(file); sendComment.fileName = file.name; } } $scope.sendComment = function(sendComment,task_key){ // $scope.alertComment[task_key] = true; console.log(task_key,sendComment); if("text" in sendComment && sendComment.text.length>0) { if("myFile" in sendComment){ if("base64" in sendComment.myFile){ if ( sendComment.myFile.base64 == null) { alert("File too large"); return; } }else { alert("File too large"); return; } notify.sendComment(sendComment,task_key);// notify.sendTaskStatusChange(submitData,task_key); } else notify.sendComment(sendComment,task_key); //notify.sendTaskStatusChange(submitData,task_key); $scope.unsetAccordion(task_key); } else{ $scope.alertBox = "לא ניתן לשלוח תגובה ריקה"; $scope.alertComment[task_key] = true; } } $scope.openFileSelect=function(ID){ document.querySelector('#'+ID).click(); } $scope.openFileandCoverttoBase64=function (model){ document.getElementById('fileInput').click(); //this work } $scope.igotdata = function (ID){ document.getElementById(ID); console.log("fileselected"); } $scope.opaqueOrNormal=function(attach){ // if(Object.prototype.toString.call(attach) == Object.prototype.toString.call([])) if(attach.length == 0){ return "opaque"; }else{ return ""; } } $scope.unsetAccordion =function(accordian){ if(SharedState.get("myAccordion") == accordian){ SharedState.setOne("myAccordion","0"); }else{ SharedState.setOne("myAccordion",accordian); SharedState.setOne("activeTab",1); } } $scope.unsetAccordionone=function(accordian,tab){ var curtab = SharedState.setOne("activeTab"); var curaccor = SharedState.get("myAccordion"); if(curaccor== accordian && tab==curtab){ SharedState.setOne("myAccordion","0"); } if(curaccor && tab!== curtab) SharedState.setOne("activeTab",tab); if(curaccor!= accordian){ SharedState.setOne("activeTab",tab); SharedState.setOne("myAccordion",accordian); } } $scope.cn = 0; $scope.formatDate = function(date){ date = date.replace(" ","T"); var rDat = new Date(date); return rDat; } $scope.todayGreater =function (date ){ datetocheck = $scope.formatDate(date); var today = new Date(); today.setHours(0,0,0,0); if(datetocheck < today){ return {'background-color':"red"}; } return {}; } $scope.alertme = function(id){ $location.path("/file/"+id); } $scope.notices = notify.notices; $scope.filter = { 'page':1 }; $scope.filter.page = 1; $scope.loadReport = function(){ if(isNaN($scope.filter.page)) $scope.filter.page = 1; $scope.filter.page = $scope.filter.page + 1; notify.listtaskviewaddrecords($scope,$scope.filter); }; $scope.search = ""; $scope.activityIds = notify.activityIds; $scope.attachments = notify.attachments; $scope.focusSearchbox = function(){ $scope.focussed = "search-box-outline"; } $scope.filterme=function(){ var myFilter = { "selectStatus" : $scope.selectStatus, "selectType":$scope.selectType, "selectSortby":$scope.selectSortby } notify.taskFilter(myFilter); if($scope.selectStatus.id !==null) $scope.filter["filter[status_id]"]=$scope.selectStatus.id; else delete $scope.filter["filter[status_id]"]; if($scope.selectType.id !==null) $scope.filter["selectby"]=notify.selectTypebyList[$scope.selectType.id]; else delete $scope.filter["selectby"]; if($scope.selectSortby.id !==null) $scope.filter["sortby"]=notify.selectSortDict[$scope.selectSortby.id]; else - delete $scope.filter["sortby"]; if( $scope.search.length>3){ $scope.filter["text_filter[subject]"] = $scope.search; }else delete $scope.filter["text_filter[subject]"]; $scope.filter['page']=1; notify.listtaskview($scope,$scope.filter); } $scope.filterme(); //notify.listtaskview($scope,{'page':1}); $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) { // Do anything $scope.processRoute() }); $scope.processRoute = function(){ if("id" in $routeParams){ if("type" in $routeParams){ if($routeParams.type=="file") $scope.unsetAccordionone($routeParams.id,5); }else $scope.unsetAccordion($routeParams.id); var elem = angular.element(document.getElementsByClassName("scrollable-content")); var scrollableContentController = elem.controller('scrollableContent'); containedElement = document.getElementById("uset-"+$routeParams.id); scrollableContentController.scrollTo(containedElement,"210"); } } $scope.scrollme = function(id){ var elem = angular.element(document.getElementsByClassName("scrollable-content")); var scrollableContentController = elem.controller('scrollableContent'); containedElement = document.getElementById(id); scrollableContentController.scrollTo(containedElement,"210"); } $scope.resetComment= function(){ $scope.newComment={}; $scope.submitData = {}; $scope.newComment.create_time = new Date(); $scope.submitData.create_time=new Date(); } $scope.resetComment() }); app.controller('loginCtrl',function($scope,$location,notify){ $scope.error_msg = ''; $scope.validateFields = function(){ if($scope.email === ''){ $scope.error_msg = 'אחד או יותר מנתוני הכניסה שהיקשת אינו נכון'; return; } if( $scope.email =="" && $scope.password=="") return; notify.login($scope.email,$scope.password,$scope); } $scope.moveToIndex = function(){ $location.path("/index"); } $scope.clearLoginCRedentials = function(){ $scope.email=''; $scope.password=''; } notify.regmeFirebase(); notify.checkIfLoggedIn($scope); }); app.controller('aboutController', function($scope,$routeParams,$location,notify) { if("id" in $routeParams){ //@todo process file notify.fetchFileDetails($scope,$routeParams.id); }else{ $location.path("/login"); } $scope.frameSrc = function(){ var url = "https://docs.google.com/gview?embedded=true&url="; return url+$scope.currentDomain+"/newtrackts/jscontrol/attachment/"+ $scope.fileinfo.id; } $scope.imageSrc=function(){ // var url = "https://docs.google.com/gview?embedded=true&url="; return $scope.currentDomain+"/newtrackts/jscontrol/attachment/"+ $scope.fileinfo.id; } $scope.currentDomain = window.location.origin; $scope.goindex = function(){ var fileinfo = $scope.fileinfo; var path = "/index"; if("task_key" in fileinfo){ path = path + "/"+fileinfo.task_key+"/file"; } $location.path(path); } $scope.imageType = function(){ if("attach_name" in $scope.fileinfo) { var nameFile = $scope.fileinfo.attach_name; var ext= nameFile.split(".")[nameFile.split(".").length-1].toUpperCase(); // var ext= $scope.fileinfo.attach_name.split(".")[1].toUpperCase(); if($scope.imageExt.includes(ext)) return true else return false; } else return false; } $scope.fileinfo = { }; $scope.imageExt = [ "ANI", "BMP", "CAL", "FAX", "GIF", "IMG", "JBG", "JPE", "JPEG", "JPG", "MAC", "PBM", "PCD", "PCX", "PCT", "PGM", "PNG", "PPM", "PSD", "RAS", "TGA", "TIFF", "WMF" ]; $scope.OtherType = function(){ return !$scope.imageType(); } });