Skip to content

Instantly share code, notes, and snippets.

@SergeyNarozhny
Last active August 29, 2015 14:25
Show Gist options
  • Save SergeyNarozhny/ea5460d23c98062f0c9f to your computer and use it in GitHub Desktop.
Save SergeyNarozhny/ea5460d23c98062f0c9f to your computer and use it in GitHub Desktop.
AngularJS mobile app example 300914_app
;(function(){
var app = angular.module("app", ['ngRoute', 'ngAnimate', 'mwl.calendar']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when("/", { templateUrl: "index.html", controller: "IndexCtrl" })
.when("/statuses", { templateUrl: "main.html", controller: "MainCtrl" })
.when("/tasks", { templateUrl: "tasks.html", controller: "TasksCtrl" })
.when("/task/:id", { templateUrl: "task.html", controller: "TasksCtrl" })
.when("/status/:id", {templateUrl: "status.html", controller: "TasksCtrl"})
.when("/comment/:id", {templateUrl: "comment.html", controller: "TasksCtrl"})
.when("/calendar", {templateUrl: "calendar.html", controller: "CalendarCtrl"})
.when("/map", {templateUrl: "map.html", controller: "MapCtrl"})
.when("/finish", {templateUrl: "finish.html", controller: "MainCtrl"})
.otherwise({ redirectTo: '/' });
$locationProvider.html5Mode(true);
}]);
app.factory('appCache', ['$cacheFactory', function($cacheFactory) {
return $cacheFactory('appData', { capacity: 100 });
}]);
app.constant("cfg", { "url": "/app2/ajax.php" });
app.service('xes', ['$http', '$q', 'appCache', 'cfg', function($http, $q, appCache, cfg){
this.checkGPRS = function()
{
if (navigator.network) return (navigator.network.connection.type == "none" ? false : true);
else return navigator.onLine;
}
this.convertCacheString = function(data)
{
var str = '?';
for (var i in data)
{
if (typeof data[i] == "string")
{
str += i + '=' + data[i].replace(/\"/g,"") + '&';
}
}
return str.substr(0,str.length-1);
}
this.send = function(data)
{
var q = $q.defer(), url = cfg.url,
datakey = url + this.convertCacheString(data),
cacheData = appCache.get(datakey),
queque = appCache.get("queque"),
xes = this;
if (this.checkGPRS())
{
if (data.request == "gtTs" && !!queque)
{
this.sendQueque(data.tasksForUpdate).then(function(res){
appCache.remove("queque");
var tasks = xes.send({ request: 'gtTs', user: data.user }); //?!
q.resolve(tasks);
});
}
else if (data.request != "gtTs" && data.request != "chSt" && cacheData)
{
//return from cache in online mode, except tasks
q.resolve(cacheData);
}
else
{
$http({
url: url,
method: "GET",
params: data,
cache: false
}).success(function(res){
appCache.put(datakey, res); //cache every request, including tasks
q.resolve(res);
});
}
}
else
{
q.resolve(cacheData);
}
return q.promise;
}
this.auth = function(user, pass)
{
return $http.post('/app2/ajax.php', { request: 'chAu', login: user, pass: pass });
}
this.logoutUser = function()
{
return $http.post('/app2/ajax.php', { request: 'lgOt' });
}
this.getStatuses = function(user)
{
return $http.post('/app2/ajax.php', { request: 'gtSt', user: user });
}
this.getEndStatuses = function(user)
{
return $http.post('/app2/ajax.php', { request: 'gtESt', user: user });
}
this.sendQueque = function(tasks)
{
return $http.post('/app2/ajax.php', { request: 'udQq', tasks: tasks });
}
this.updatePhoto = function(task, filename)
{
return $http.post('/app2/ajax.php', { request: 'udPh', task: task, filename: filename });
}
this.getUser = function()
{
return this.send({ request: 'gtUs' });
}
this.convertDate = function(str)
{
if (typeof str != "object")
{
var arr = str.split(" "), arr2 = arr[0].split(".");
return new Date(arr2[1] + "/" + arr2[0] + "/" + arr2[2] + " " + arr[1]);
}
return false;
}
this.getTasks = function(params)
{
if (typeof params == "string")
{
return this.send({ request: 'gtTs', user: params });
}
else
{
return this.send({ request: 'gtTs', user: params[0], tasksForUpdate: params[1] });
}
}
this.createMyDatetime = function()
{
var dt = new Date();
var dtstring = this.pad(dt.getDate())
+ '.' + this.pad(dt.getMonth()+1)
+ '.' + dt.getFullYear()
+ ' ' + dt.getHours()
+ ':' + this.pad(dt.getMinutes())
+ ':' + this.pad(dt.getSeconds());
return dtstring;
}
this.pad = function(number)
{
var str = '' + number;
while (str.length < 2)
{
str = '0' + str;
}
return str;
}
}]);
app.directive('gMap', ['$routeParams', function($routeParams){
return {
restrict: 'EA',
scope: {
latlng : "="
},
link: function ($scope, element, attrs) {
if ($routeParams.id)
{
var mLatLng = new google.maps.LatLng($scope.latlng[0].trim(), $scope.latlng[1].trim()),
mapOptions = { zoom: 16, center: mLatLng, mapTypeId: google.maps.MapTypeId.ROADMAP };
$scope.map = new google.maps.Map(element[0], mapOptions);
var marker = new google.maps.Marker({
position: mLatLng,
map: $scope.map,
title: "Marker"
});
}
}
}
}]);
app.directive('gMapBig', ['xes', function(xes){
return {
restrict: 'EA',
link: function ($scope, element, attrs) {
xes.getUser().then(function(user){
$scope.user = user.replace(/\"/g,"");
xes.getTasks($scope.user).then(function(tasks){
$scope.tasks = tasks.TASKS;
var mapOptions = { zoom: 15, center: new google.maps.LatLng(38.3444434, -0.484984), mapTypeId: google.maps.MapTypeId.ROADMAP },
infowindow = new google.maps.InfoWindow({
maxWidth: 400,
content: ""
}),
innerTasks = [];
$scope.map = new google.maps.Map(element[0], mapOptions);
for (var i = 0; i < $scope.tasks.length; i++)
{
var bundle = {};
if(~$scope.tasks[i]['UF_TASK_ADDRESS'].indexOf(', '))
{
bundle['latLng'] = $scope.tasks[i]['UF_TASK_ADDRESS'].split(', ');
}
bundle['task_id'] = $scope.tasks[i]['ID'];
bundle['task_title'] = $scope.tasks[i]['TITLE'];
bundle['task_desc'] = "<div class='map-task-block'>" +
"<a href='/app/task.php?taskID=" + $scope.tasks[i]['ID'] + "'>" + $scope.tasks[i]['TITLE'] + "</a><br/>" +
"<div class='map-task-title'><span>Тип: " + $scope.tasks[i]['UF_TASKS_TYPE_WORK'] + "</span></div>" +
"<div class='map-task-title'><span>Заказчик: " + $scope.tasks[i]['UF_TASK_SUPPLIER'] + "</span></div>" +
"<div class='map-task-title'><span>Адрес: " + $scope.tasks[i]['UF_TASK_ADDRESS_STR'] + "</span></div>" +
"<div class='map-task-desc'>" + $scope.tasks[i]['DESCRIPTION'] + "</div>" +
"</div>";
innerTasks.push(bundle);
}
for (var i = 0; i < innerTasks.length; i++)
{
(function(){
var nx = i,
marker = new google.maps.Marker({
position: new google.maps.LatLng(innerTasks[nx]['latLng'][0], innerTasks[nx]['latLng'][1]),
title: "Title",
map: $scope.map,
draggable: false,
});
google.maps.event.addListener(marker, 'click', function(){
infowindow.setContent(innerTasks[nx]['task_desc']);
infowindow.open($scope.map, marker);
});
}());
}
if(innerTasks[i - 1])
{
var latLng = innerTasks[i - 1].latLng.toString();
latLng = latLng.split(",");
$scope.map.setCenter(new google.maps.LatLng(latLng[0], latLng[1]));
}
});
});
}
}
}]);
app.controller("IndexCtrl", ['$scope', '$log', '$location', 'xes', function($scope, $log, $location, xes){
$scope.goto = function(view)
{
$location.path(view);
}
$scope.checkAuth = function(first)
{
xes.auth($scope.login, $scope.pass).then(function(res){
if (res.data.TYPE == "ERROR")
{
if (first) $scope.showAuth = 1;
else $scope.error = res.data.MESSAGE.replace(/<\/?[^>]+(>|$)/g, "");
}
else
{
$scope.user = !!res.data.USER ? res.data.USER : res.data;
window.app.exec(...);
$scope.goto('statuses/');
}
});
}
$scope.checkAuth(true);
}]);
app.controller("MainCtrl", ['$http', '$scope', '$log', '$location', 'xes', function($http, $scope, $log, $location, xes){
$scope.pth = $location.$$absUrl;
$scope.goto = function(view)
{
$location.path(view);
}
$scope.addStatus = function(index)
{
$scope.statuses[index].CHECKED = 1;
}
$scope.canBeginWork = function()
{
if ($scope.statuses)
{
for (var i=0; i < $scope.statuses.length; i++)
{
if ($scope.statuses[i].CHECKED != 1) return true;
}
}
return false;
}
$scope.endWork = function()
{
if (xes.checkGPRS())
{
window.app.exec("stopSendService");
xes.logoutUser().then(function(res){
$scope.goto('/');
});
}
}
xes.getUser().then(function(user){
$scope.user = user.replace(/\"/g,"");
if (~$location.$$path.indexOf("statuses"))
{
xes.getStatuses($scope.user).then(function(statuses){
$scope.statuses = statuses.data;
});
}
else if (~$location.$$path.indexOf("finish"))
{
xes.getEndStatuses($scope.user).then(function(statuses){
$scope.statuses = statuses.data;
});
}
});
$log.log($scope);
}]);
app.controller("TasksCtrl", ['$http', '$scope', '$log', '$location', 'xes', '$routeParams', '$filter', 'appCache', 'cfg', '$window', '$q', function($http, $scope, $log, $location, xes, $routeParams, $filter, appCache, cfg, $window, $q){
$scope.rt = {};
$scope.successFeedback = "N";
$scope.ests = [
{id:'excelent', name:'Отлично', active:false},
{id:'good', name:'Хорошо', active:false},
{id:'bad', name:'Плохо', active:false}
];
$scope.task = [];
$scope.st = [];
$scope.pth = $location.$$absUrl;
$scope.showMenu = false;
$scope.readyStatuses = false;
$scope.goto = function(view, target)
{
if (arguments.length == 1)
{
$location.path(view);
}
else if (arguments.length == 2)
{
$location.path(view + target + "/");
}
}
$scope.isOnline = function()
{
return xes.checkGPRS();
}
$scope.estSelect = function(id)
{
for (var i = 0; i < $scope.ests.length; i++)
{
if ($scope.ests[i].id == id) { $scope.ests[i].active = true; $scope.estselected = $scope.ests[i].name; }
else $scope.ests[i].active = false;
}
}
$scope.findTask = function(id)
{
var index;
for (var i = 0; i < $scope.tasks.length; i++)
{
if ($scope.tasks[i].ID == id) index = i;
}
$scope.task.push($scope.tasks[index]);
}
$scope.findPrice = function()
{
for (var i = 0; $scope.prices.length; i++)
{
if ($scope.prices[i].VAL == $scope.task[0].UF_TASKS_TYPE_WORK2) return $scope.prices[i].DESC;
}
}
$scope.addInQueque = function(data, quequename)
{
var arr = appCache.get(quequename);
if (!arr) arr = [];
if (arr.indexOf(data) == -1)
{
arr.push(data);
appCache.put(quequename, arr);
}
}
$scope.checkQuequeParams = function()
{
var arr = [], cache = appCache.get("queque"), files = appCache.get("filesqueque");
if (!$scope.tasks && !!cache)
{
var tasks = appCache.get(cfg.url + "?request=gtTs&user=" + $scope.user);
$scope.tasks = tasks.TASKS;
// ::TODO:: how new/changed tasks will come out from cache?!
}
if (xes.checkGPRS() && !!files)
{
for (var i = 0; i < files.length; i++)
{
$scope.uploadPhoto(files[i].taskid, files[i].file);
}
appCache.remove("filesqueque");
}
if (xes.checkGPRS() && !!cache && !!$scope.tasks)
{
for (var i = 0; i < cache.length; i++)
{
for (var z = 0; z < $scope.tasks.length; z++)
{
if ((cache[i] != "NaN" && cache[i] == $scope.tasks[z].ID)
|| (cache[i] == "NaN" && !!!$scope.tasks[z].ID)) arr.push($scope.tasks[z]);
}
}
return [$scope.user, arr];
}
else
{
return $scope.user;
}
}
$scope.getPrices = function()
{
return xes.send({ request: 'gtPr' });
}
$scope.repeatTask = function()
{
$scope.changeTimeDiff();
//SRF
$scope.rt.date2 = $filter('date')($scope.rt.date, 'dd.MM.yyyy');
$scope.rt.time2 = $filter('date')($scope.rt.time, 'HH:mm:ss');
if (xes.checkGPRS())
{
xes.send({ request: 'rpTs', form: $scope.rt, task: $scope.task[0].ID, timesec: $scope.task[0].TIME_DIFF }).then(function(res){
$scope.goto("tasks/");
});
}
else
{
var task = angular.copy($scope.task[0]);
for (var i=0, arr=['ID', 'UF_TASK_STATUS', 'UF_TASK_STATUS_LIST']; i < arr.length; i++)
{
delete task[arr[i]];
}
var date = $scope.rt.date2 + " " + $scope.rt.time2, arEndHour = $scope.rt.time2.split(":"),
dateEnd = $scope.rt.date2 + " " + (parseInt($scope.rt.duration) + parseInt(arEndHour[0])) + ":" + arEndHour[1] + ":00";
task.STATUS = "-2";
task.TITLE = "Re-Task " + task.TITLE + "/1";
task.DESCRIPTION = $scope.rt.comment;
task.START_DATE_PLAN = date;
task.DURATION_PLAN = $scope.rt.duration;
task.END_DATE_PLAN = dateEnd;
task.UF_TASKS_TYPE_WORK = $scope.rt.seltype;
task.UF_TASKS_TYPE_WORK2 = $scope.wtypes[$scope.rt.seltype];
$scope.tasks.push(task);
$scope.addInQueque("NaN", "queque");
$scope.task[0].CLOSED_DATE = xes.createMyDatetime();
$scope.task[0].STATUS = 5;
$scope.task[0].UF_TASK_STATUS = "44";
$scope.task[0].UF_TASK_STATUS_LIST = $scope.statuses['44'];
//++
$scope.task[0].UF_MYTOTALTIME = parseInt($scope.task[0].UF_MYTOTALTIME) + parseInt($scope.task[0].TIME_DIFF);
$scope.task[0].UF_MYTIME = xes.createMyDatetime();
$scope.addInQueque($scope.task[0].ID, "queque");
$scope.goto("tasks/");
}
}
$scope.makeAction = function(statusID)
{
for (var i = 0; i < $scope.st.length; i++)
{
if ($scope.st[i].ID == statusID) $scope.st[i].ACTIVE = 1;
else $scope.st[i].ACTIVE = 0;
}
$scope.selstatus = statusID;
if (statusID == '43')
{
$scope.goto("comment/", $scope.task[0].ID);
}
else if (statusID == '44')
{
$scope.needForm = 1;
}
else
{
$scope.needForm = 0;
$scope.changeStatus('task/', $scope.task[0].ID);
}
}
$scope.changeTimeDiff = function()
{
if ($scope.task[0].UF_MYTIME)
{
$scope.task[0].TIME_DIFF = (xes.convertDate(xes.createMyDatetime()) - xes.convertDate($scope.task[0].UF_MYTIME)) / 1000;
}
}
$scope.changeStatus = function(where, target, status)
{
$scope.changeTimeDiff();
//SRF
var stt = (status ? status : $scope.selstatus);
if (xes.checkGPRS())
{
xes.send({ request: 'chSt', status: stt, task: $scope.task[0].ID, oldstatus: $scope.task[0].UF_TASK_STATUS, timesec: $scope.task[0].TIME_DIFF }).then(function(res){
if (where != "no") $scope.goto(where, target);
});
}
else
{
if (stt == '41' || stt == '42')
{
$scope.task[0].CLOSED_DATE = null;
if ($scope.task[0].UF_TASK_STATUS != '41' && $scope.task[0].UF_TASK_STATUS != '42') $scope.task[0].DATE_START = xes.createMyDatetime();
$scope.task[0].STATUS = 3;
}
else if (stt == '43' || stt == '44')
{
$scope.task[0].CLOSED_DATE = xes.createMyDatetime();
$scope.task[0].STATUS = 5;
}
$scope.task[0].UF_TASK_STATUS = stt;
$scope.task[0].UF_TASK_STATUS_LIST = $scope.statuses[stt];
//++
$scope.task[0].UF_MYTOTALTIME = parseInt($scope.task[0].UF_MYTOTALTIME) + parseInt($scope.task[0].TIME_DIFF);
$scope.task[0].UF_MYTIME = xes.createMyDatetime();
$scope.addInQueque($scope.task[0].ID, "queque");
if (where != "no") $scope.goto(where, target);
}
}
$scope.leaveFeedback = function()
{
//SRF
$scope.changeStatus('no', $scope.task[0].ID, '43');
if (xes.checkGPRS())
{
xes.send({ request: 'adTs', comment: $scope.rt.commtxt, mark: $scope.estselected, task: $scope.task[0].ID }).then(function(res){
$scope.successFeedback = "Y";
});
}
else
{
$scope.task[0].UF_TASK_MARK_NUM = $scope.estselected;
$scope.task[0].UF_TASK_MARK_TXT = $scope.rt.commtxt;
$scope.addInQueque($scope.task[0].ID, "queque");
$scope.successFeedback = "Y";
}
}
$scope.getSessid = function()
{
var q = $q.defer();
xes.auth($scope.login, $scope.pass).then(function(res){
if (res.data.TYPE != "ERROR" && isNaN(res.data.SESSID)) $scope.sessid = res.data.SESSID;
$scope.uploadUrl = "http://" + $location.$$host + "/mobile/crm/contact/file.php?id=" + $scope.user + "&sessid=" + $scope.sessid;
q.resolve();
});
return q.promise;
}
$scope.uploadPhoto = function(taskid, fileURI)
{
var ft = new FileTransfer(), options = new FileUploadOptions();
options.fileKey = 'file';
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.params = {};
options.chunkedMode = false;
if (!$scope.uploadUrl)
{
// Will be used when 'filesqueque' queque is executed!
$scope.getSessid().then(function(){
ft.upload(fileURI, $scope.uploadUrl,
function(result){
var response = decodeURIComponent(result.response),
info = eval('(' + response + ')');
$scope.photofile = info.showUrl;
xes.updatePhoto(taskid, $scope.photofile);
for (var i=0; i < $scope.tasks.length; i++)
{
if ($scope.tasks[i].ID == taskid)
{
$scope.tasks[i].UF_PHOTO_AJAX = "";
$scope.tasks[i].UF_PHOTO.push({ SRC: $scope.photofile });
}
}
$scope.activeProcess = false;
},
function(error){ alert("Ошибка! " + error + " Повторите операцию ещё раз."); },
options
);
});
}
else
{
ft.upload(fileURI, $scope.uploadUrl,
function(result){
var response = decodeURIComponent(result.response),
info = eval('(' + response + ')');
$scope.photofile = info.showUrl;
xes.updatePhoto(taskid, $scope.photofile).then(function(id){
$scope.task[0].UF_PHOTO.push({ SRC: $scope.photofile });
$scope.activeProcess = false;
});
},
function(error){ alert("Ошибка! " + error + " Повторите операцию ещё раз."); },
options
);
}
}
$scope.showPhotoDialog = function()
{
var el = angular.element(document.querySelector('#task-files'));
$scope.activeProcess = true;
window.app.takePhoto(
{
source: 1,
destinationType: 1,
callback: function(fileURI)
{
if (xes.checkGPRS())
{
$scope.uploadPhoto($scope.task[0].ID, fileURI);
}
else
{
$scope.addInQueque({ taskid: $scope.task[0].ID, file: fileURI }, "filesqueque");
$scope.task[0].UF_PHOTO_AJAX = "Фото загружено и будет сохранено при появлении Интернета.";
}
},
fail: function(err)
{
el.append("err: " + angular.toJson(err) + "<br/>");
}
});
}
$scope.toggleMenu = function()
{
$scope.showMenu = !$scope.showMenu;
}
$scope.goBack = function()
{
if (xes.checkGPRS()) $window.history.back();
else $scope.goto("tasks/");
}
$scope.goTask = function(id)
{
if (id) $scope.goto("task/", id);
}
xes.getUser().then(function(user){
$scope.user = user.replace(/\"/g,"");
xes.getTasks($scope.checkQuequeParams()).then(function(tasks){
$scope.tasks = tasks.TASKS;
$scope.wtypes = tasks.WORK_TYPES;
$scope.statuses = tasks.STATUSES;
$scope.getPrices().then(function(prices){
$scope.prices = prices;
});
if ($routeParams.id && $scope.tasks.length > 1)
{
$scope.findTask($routeParams.id);
for (var i in $scope.statuses)
{
$scope.st.push({ 'ID':i, 'VAL': $scope.statuses[i], 'ACTIVE': (i == $scope.task[0].UF_TASK_STATUS ? true : false) });
$scope.readyStatuses = true;
}
$scope.currentstatus = $scope.task[0].UF_TASK_STATUS_LIST;
if ($scope.task.length == 1 && !!$scope.task[0].DATE_START)
{
// ::TODO:: DATE_START can be null ?! Mb if false equals to START_DATE_PLAN ?!
$scope.difftimesec = Math.abs(xes.convertDate(xes.createMyDatetime()) - xes.convertDate($scope.task[0].DATE_START)) / 1000;
$scope.difftimehour = $scope.difftimesec < 3600 ? 1 : ($scope.difftimesec / 3600);
$scope.diffost = $scope.difftimesec % 3600;
if ($scope.diffost >= 1800) $scope.difftimehour += 1;
$scope.difftimehour = Math.round($scope.difftimehour);
// ::TODO:: calc price here ?!
$scope.getPrices().then(function(prices){
$scope.prices = prices;
$scope.price = $scope.findPrice();
$scope.total = parseInt($scope.price) * +$scope.difftimehour;
});
}
$scope.getSessid();
}
});
});
$log.log($scope);
}]);
app.controller("CalendarCtrl", ['$scope', '$log', '$location', 'xes', 'moment', '$window', function($scope, $log, $location, xes, moment, $window){
moment.locale('ru', {
week : { dow : 1 },
});
$scope.calendarView = 'month';
$scope.calendarDay = new Date();
$scope.events = [];
$scope.showMenu = false;
$scope.toggleMenu = function()
{
$scope.showMenu = !$scope.showMenu;
}
$scope.goto = function(view, target)
{
if (arguments.length == 1)
{
$location.path(view);
}
else if (arguments.length == 2)
{
$location.path(view + target + "/");
}
}
$scope.setCalendarToToday = function()
{
$scope.calendarDay = new Date();
}
$scope.eventClicked = function(event)
{
$scope.goto("task/", event.inner_id);
}
$scope.changeCalView = function(mode)
{
$scope.calControlTitle(mode);
$scope.calendarView = mode;
}
$scope.calControlTitle = function(mode)
{
var monthNames = ["январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"],
or = ($scope.calendarControl ? $scope.calendarControl.getTitle() : monthNames[(new Date().getMonth())]),
orig = or.split(" "),
res = '';
if (!arguments.length) var mode = $scope.calendarView;
switch (mode)
{
case 'month':
res = $scope.rightMonthEndings(orig[0]) + " " + orig[1];
break;
case 'week':
res = orig[1] + " неделя " + orig[3] + " года";
break;
default:
res = or;
break;
}
return res;
}
$scope.rightMonthEndings = function(str)
{
var bg = ['январ', 'феврал', 'март', 'апрел', 'ма', 'июн', 'июл', 'август', 'сентябр', 'октябр', 'ноябр', 'декабр'],
en = ['ь', 'ь', '', 'ь', 'й', 'ь', 'ь', '', 'ь', 'ь', 'ь', 'ь'],
part = str.substr(0,str.length-1), index = bg.indexOf(part),
res = bg[index] + en[index];
return res;
}
$scope.goBack = function()
{
if (xes.checkGPRS()) $window.history.back();
else $scope.goto("tasks/");
}
xes.getUser().then(function(user){
$scope.user = user.replace(/\"/g,"");
xes.getTasks($scope.user).then(function(tasks){
$scope.tasks = tasks.TASKS;
for (var i = 0; i < $scope.tasks.length; i++)
{
if ($scope.tasks[i].STATUS != "5" || !$scope.tasks[i].CLOSED_DATE)
{
if (!$scope.tasks[i].START_DATE_PLAN) continue;
var arEndDate = $scope.tasks[i].START_DATE_PLAN.split(" "), arEndHour = arEndDate[1].split(":"),
dateEnd = $scope.tasks[i].START_DATE_PLAN + " " + (+$scope.tasks[i].DURATION_PLAN + arEndHour[0]) + ":" + arEndHour[1] + ":00";
// The type of the event (determines its color). Can be important, warning, info, inverse, success or special
// If calendar-edit-event-html is set and this field is explicitly set to false then dont make it editable
// If calendar-delete-event-html is set and this field is explicitly set to false then dont make it deleteable
$scope.events.push({
title: 'Задача #' + $scope.tasks[i].ID,
type: 'info',
inner_id: $scope.tasks[i].ID,
starts_at: xes.convertDate($scope.tasks[i].START_DATE_PLAN),
ends_at: xes.convertDate(dateEnd),
editable: false,
deletable: false
});
}
}
});
});
$log.log($scope);
}]);
app.controller("MapCtrl", ['$http', '$scope', '$log', '$location', '$window', 'xes', function($http, $scope, $log, $location, $window, xes){
$scope.showMenu = false;
$scope.toggleMenu = function()
{
$scope.showMenu = !$scope.showMenu;
}
$scope.goto = function(view)
{
$location.path(view);
}
$scope.goBack = function()
{
if (xes.checkGPRS()) $window.history.back();
else $scope.goto("tasks/");
}
$log.log($scope);
}]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment