'use strict'; angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', 'Forms', '$stateParams', '$interval', function ($rootScope, $http, Forms, $stateParams, $interval) { return { templateUrl: 'modules/forms/admin/views/directiveViews/form/edit-submissions-form.client.view.html', restrict: 'E', scope: { user:'=', myform: '=' }, controller: function($scope){ $scope.table = { masterChecker: false, rows: [] }; $scope.analyticsData = { deviceStatistics: [], globalStatistics: [] }; $scope.deletionInProgress = false; $scope.waitingForDeletion = false; //Waits until deletionInProgress is false before running getSubmissions $scope.$watch("deletionInProgress",function(newVal, oldVal){ if(newVal !== oldVal && newVal === false && $scope.waitingForDeletion) { $scope.getSubmissions(); $scope.waitingForDeletion = false; } }); $scope.handleSubmissionsRefresh = function(){ if(!$scope.deletionInProgress) { $scope.getSubmissions(); } else { $scope.waitingForDeletion = true; } }; /* ** Analytics Functions */ var formatGlobalStatistics = function(globalStatData){ if(!globalStatData || !globalStatData.length){ return { visits: 0, responses: 0, conversion_rate: 0, average_time: 0 }; } return globalStatData[0]; } var formatDeviceStatistics = function(deviceStatData){ var newStatItem = function(){ return { visits: 0, responses: 0, conversion_rate: 0, average_time: 0, total_time: 0 }; }; var stats = { desktop: newStatItem(), tablet: newStatItem(), phone: newStatItem(), other: newStatItem() }; if(deviceStatData && deviceStatData.length){ for(var i=0; i