2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
23 class CommonWidgetController {
24 constructor(dashboardService, $scope, message, $q, $http, conf, $filter,confirmBoxService,$log) {
25 $scope.widgetType = message.type;
26 $scope.widgetTypeDisplay = message.type;
27 $scope.modflag = false;
29 switch (message.type) {
31 $scope.widgetTypeDisplay = 'Events'
34 $scope.widgetTypeDisplay = 'News'
36 case 'IMPORTANTRESOURCES':
37 $scope.widgetTypeDisplay = 'Resources'
41 $scope.widgetData = [];
42 dashboardService.getCommonWidgetData(message.type)
43 .then(function (res) {
44 // console.log('CommonWidgetController: result is ' + res);
45 $scope.widgetData = res.response.items;
50 $scope.setEdit = function(index) {
52 //for(var i=0; i<$scope.widgetData )
54 if($scope.modflag === false){
55 $scope.widgetData[index].showEdit = true;
56 $scope.modflag = true;
60 $scope.modify = function(index) {
62 $scope.widgetObject = {};
63 $scope.widgetObject.id = $scope.widgetData[parseInt(index)].id;
64 $scope.widgetObject.category = $scope.widgetData[parseInt(index)].category;
65 $scope.widgetObject.title = $scope.widgetData[parseInt(index)].title;
66 $scope.widgetObject.href = $scope.widgetData[parseInt(index)].href;
67 $scope.widgetObject.eventDate = $scope.widgetData[parseInt(index)].eventDate;
68 $scope.widgetObject.content = $scope.widgetData[parseInt(index)].content;
69 $scope.widgetObject.sortOrder = $scope.widgetData[parseInt(index)].sortOrder;
71 var validateMsg = $scope.validateWidgetObject($scope.widgetObject);
73 confirmBoxService.showInformation(validateMsg).then(isConfirmed => {return;});
77 dashboardService.saveCommonWidgetData($scope.widgetObject)
79 if (res.status == 'OK') {
80 dashboardService.getCommonWidgetData(message.type)
82 $scope.widgetData = res.response.items;
83 $scope.modflag = false;
84 $scope.cancelEdit(index);
89 confirmBoxService.showInformation("Save failed").then(isConfirmed => {return;});
96 $scope.newWidgetObject = {};
98 // Answers string error if validation fails;
99 // answers null if all is well.
100 $scope.validateWidgetObject = function(wo) {
101 if (wo.title == null || wo.title == '')
102 return "Please enter a title.";
103 if (wo.href == null || wo.href == '' || !validateUrl(wo.href))
104 return "Please enter a valid URL that starts with http.";
105 if (wo.sortOrder == null || wo.sortOrder == '' || isNaN(parseInt(wo.sortOrder)))
106 return "Please enter a number for the sort order.";
107 if (wo.category=='EVENTS') {
108 if (wo.eventDate == null || wo.eventDate == '')
109 return "Please enter a date for the event.";
110 // Parses and normalizes the date with rollover.
111 var filteredDate = $filter('date')(wo.eventDate, "yyyy-MM-dd");
112 // $log.debug('dashboard-widget-controller: date filter yields ' + filteredDate);
113 // The date picker shows mm/dd/yy.
114 if (filteredDate == null || filteredDate.length != 10)
115 return "Please enter a valid date as YYYY-MM-DD";
116 if (wo.content==null || wo.content=='')
117 return "Please enter content for the event.";
122 $scope.saveNew = function() {
123 $scope.newWidgetObject.category = message.type;
124 // $log.info($scope.newWidgetObject);
125 var validateMsg = $scope.validateWidgetObject($scope.newWidgetObject);
127 confirmBoxService.showInformation(validateMsg).then(isConfirmed => {return;});
130 // Transform date into expected storage format
131 $scope.newWidgetObject.eventDate = $filter('date')($scope.newWidgetObject.eventDate, "yyyy-MM-dd");
133 dashboardService.saveCommonWidgetData($scope.newWidgetObject)
135 if (res.status == 'OK') {
136 confirmBoxService.showInformation('You have added a new item').then(isConfirmed => {
138 dashboardService.getCommonWidgetData(message.type)
140 $scope.widgetData = res.response.items;
141 $scope.newWidgetObject = {};
145 confirmBoxService.showInformation("Save failed").then(isConfirmed => {return;});
151 $scope.remove = function(index) {
152 var confirmMsg = 'Are you sure you want to delete this item from the list?' + ' Press OK to delete.';
153 confirmBoxService.confirm(confirmMsg).then(function (confirmed) {
154 if (confirmed == true) {
155 $scope.widgetObject = {};
156 $scope.widgetObject.id = $scope.widgetData[parseInt(index)].id;
157 $scope.widgetObject.category = $scope.widgetData[parseInt(index)].category;
158 $scope.widgetObject.title = $scope.widgetData[parseInt(index)].title;
159 $scope.widgetObject.href = $scope.widgetData[parseInt(index)].href;
160 $scope.widgetObject.sortOrder = $scope.widgetData[parseInt(index)].sortOrder;
163 dashboardService.removeCommonWidgetData($scope.widgetObject)
165 dashboardService.getCommonWidgetData(message.type)
167 $scope.widgetData = res.response.items;
168 $scope.cancelEdit(index);
175 $scope.closeDialog = function(){
176 $scope.closeThisDialog( $scope.widgetData);
178 $scope.deleteSpeedDial = function(widget){
182 $scope.manage = function(index) {
183 $scope.modflag = true;
185 var thisdata = $scope.widgetData[index];
186 $scope.editMode=true;
187 var category = "#category"+index;
188 var categoryEdit = "#categoryEdit"+index;
190 var title = "#title"+index;
191 var titleEdit = "#titleEdit"+index;
193 var url = "#href"+index;
194 var urlEdit = "#hrefEdit"+index;
196 var order = "#order"+index;
197 var orderEdit = "#orderEdit"+index;
199 var eventDate = "#eventDate"+index;
200 var eventDateEdit = "#eventDateEdit"+index;
203 var dsavebutton ="#savebutton"+index;
204 var dremovebutton="#removebutton"+index;
205 var dmanagebutton="#managebutton"+index;
206 var deditRbutton="#editRbutton"+index;
208 $(title).css('display', 'none');
209 $(titleEdit).css('display', 'inherit');
210 $(url).css('display', 'none');
211 $(urlEdit).css('display', 'inherit');
212 $(order).css('display', 'none');
213 $(orderEdit).css('display', 'inherit');
214 $(eventDate).css('display', 'none');
215 $(eventDateEdit).css('display', 'inherit');
217 $(dsavebutton).css('display', 'inherit');
218 $(dremovebutton).css('display', 'inherit');
219 $(dmanagebutton).css('display', 'none');
220 $(deditRbutton).css('display', 'inherit');
224 $scope.cancelEdit = function(index) {
226 $scope.editMode=false;
227 var category = "#category"+index;
228 var categoryEdit = "#categoryEdit"+index;
230 var title = "#title"+index;
231 var titleEdit = "#titleEdit"+index;
233 var url = "#href"+index;
234 var urlEdit = "#hrefEdit"+index;
236 var order = "#order"+index;
237 var orderEdit = "#orderEdit"+index;
239 var eventDate = "#eventDate"+index;
240 var eventDateEdit = "#eventDateEdit"+index;
242 var dsavebutton ="#savebutton"+index;
243 var dremovebutton ="#removebutton"+index;
244 var dmanagebutton="#managebutton"+index;
245 var deditRbutton="#editRbutton"+index;
247 $(title).css('display', 'inherit');
248 $(titleEdit).css('display', 'none');
250 $(url).css('display', 'inherit');
251 $(urlEdit).css('display', 'none');
253 $(order).css('display', 'inherit');
254 $(orderEdit).css('display', 'none');
256 $(eventDate).css('display', 'inherit');
257 $(eventDateEdit).css('display', 'none');
259 $(dsavebutton).css('display', 'none');
260 $(dremovebutton).css('display', 'none');
261 $(dmanagebutton).css('display', 'inherit');
262 $(deditRbutton).css('display', 'none');
266 $scope.popupConfirmWin = function(title, msgBody, callback){
267 modalService.popupConfirmWin.apply(null, arguments);
271 CommonWidgetController.$inject = ['dashboardService', '$scope', 'message', '$q', '$http', 'conf', '$filter','confirmBoxService','$log'];
272 angular.module('ecompApp').controller('CommonWidgetController', CommonWidgetController);
275 angular.module('ecompApp').filter('cut', function () {
276 return function (value, wordwise, max, tail) {
277 if (!value) return '';
279 max = parseInt(max, 10);
280 if (!max) return value;
281 if (value.length <= max) return value;
283 value = value.substr(0, max);
285 var lastspace = value.lastIndexOf(' ');
286 if (lastspace != -1) {
287 //Also remove . and , so its gives a cleaner result.
288 if (value.charAt(lastspace-1) == '.' || value.charAt(lastspace-1) == ',') {
289 lastspace = lastspace - 1;
291 value = value.substr(0, lastspace);
295 return value + (tail || ' …');
299 angular.module('ecompApp').controller('DatePickerController', function ($scope, uibDateParser) {
300 $scope.today = function() {
301 $scope.dt = new Date();
305 $scope.clear = function() {
309 $scope.inlineOptions = {
310 customClass: getDayClass,
315 $scope.dateOptions = {
316 dateDisabled: disabled,
322 // Disable weekend selection
323 function disabled(data) {
324 var date = data.date,
326 return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
329 $scope.toggleMin = function() {
330 $scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null : new Date();
331 $scope.dateOptions.minDate = $scope.inlineOptions.minDate;
336 $scope.open1 = function() {
337 // console.log('In open1');
338 $scope.popup1.opened = true;
341 $scope.open2 = function() {
342 // console.log('In open2');
343 $scope.popup2.opened = true;
347 $scope.setDate = function(year, month, day) {
348 $scope.dt = new Date(year, month, day);
351 $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
352 $scope.format = $scope.formats[3];
353 $scope.altInputFormats = ['M!/d!/yyyy'];
363 var tomorrow = new Date();
364 tomorrow.setDate(tomorrow.getDate() + 1);
365 var afterTomorrow = new Date();
366 afterTomorrow.setDate(tomorrow.getDate() + 1);
378 function getDayClass(data) {
379 var date = data.date,
381 if (mode === 'day') {
382 var dayToCheck = new Date(date).setHours(0,0,0,0);
384 for (var i = 0; i < $scope.events.length; i++) {
385 var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
387 if (dayToCheck === currentDay) {
388 return $scope.events[i].status;
399 function toggleCollapsible(id, clickedIconId, subtitutingIconId){
401 $("#"+clickedIconId).toggle();
402 $("#"+subtitutingIconId).toggle();
403 setTimeout(function(){focusFirstEle(id);}, 1000);
406 function focusFirstEle(id){
407 var focusItems = $("#"+id).find(":focusable");
408 for(var i=0; i<focusItems.length; i++){
409 if(!isHidden(focusItems[i])){
410 var targetClassName = focusItems[i].className;
411 if(targetClassName!='collapsibleArrow'){
412 focusItems[i].focus();
419 function validateUrl(value){
420 return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\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