2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
41 class CommonWidgetController {
42 constructor(dashboardService, $scope, message, $q, $http, conf, $filter,confirmBoxService,$log) {
43 $scope.widgetType = message.type;
44 $scope.widgetTypeDisplay = message.type;
45 $scope.modflag = false;
47 switch (message.type) {
49 $scope.widgetTypeDisplay = 'Events'
52 $scope.widgetTypeDisplay = 'News'
54 case 'IMPORTANTRESOURCES':
55 $scope.widgetTypeDisplay = 'Resources'
59 $scope.widgetData = [];
60 dashboardService.getCommonWidgetData(message.type)
61 .then(function (res) {
62 // console.log('CommonWidgetController: result is ' + res);
63 $scope.widgetData = res.response.items;
68 $scope.setEdit = function(index) {
70 //for(var i=0; i<$scope.widgetData )
72 if($scope.modflag === false){
73 $scope.widgetData[index].showEdit = true;
74 $scope.modflag = true;
78 $scope.modify = function(index) {
80 $scope.widgetObject = {};
81 $scope.widgetObject.id = $scope.widgetData[parseInt(index)].id;
82 $scope.widgetObject.category = $scope.widgetData[parseInt(index)].category;
83 $scope.widgetObject.title = $scope.widgetData[parseInt(index)].title;
84 $scope.widgetObject.href = $scope.widgetData[parseInt(index)].href;
85 $scope.widgetObject.eventDate = $scope.widgetData[parseInt(index)].eventDate;
86 $scope.widgetObject.content = $scope.widgetData[parseInt(index)].content;
87 $scope.widgetObject.sortOrder = $scope.widgetData[parseInt(index)].sortOrder;
89 var validateMsg = $scope.validateWidgetObject($scope.widgetObject);
91 confirmBoxService.showInformation(validateMsg).then(isConfirmed => {return;});
95 dashboardService.saveCommonWidgetData($scope.widgetObject)
97 if (res.status == 'OK') {
98 dashboardService.getCommonWidgetData(message.type)
100 $scope.widgetData = res.response.items;
101 $scope.modflag = false;
102 $scope.cancelEdit(index);
107 confirmBoxService.showInformation("Save failed. " +res.message).then(isConfirmed => {return;});
114 $scope.newWidgetObject = {};
116 // Answers string error if validation fails;
117 // answers null if all is well.
118 $scope.validateWidgetObject = function(wo) {
119 if (wo.title == null || wo.title == '')
120 return "Please enter a title.";
121 if (wo.href == null || wo.href == '' || !validateUrl(wo.href))
122 return "Please enter a valid URL that starts with http.";
123 if (wo.sortOrder == null || wo.sortOrder == '' || isNaN(parseInt(wo.sortOrder)))
124 return "Please enter a number for the sort order.";
125 if (wo.category=='EVENTS') {
126 if (wo.eventDate == null || wo.eventDate == '')
127 return "Please enter a date for the event.";
128 // Parses and normalizes the date with rollover.
129 var filteredDate = $filter('date')(wo.eventDate, "yyyy-MM-dd");
130 // $log.debug('dashboard-widget-controller: date filter yields ' + filteredDate);
131 // The date picker shows mm/dd/yy.
132 if (filteredDate == null || filteredDate.length != 10)
133 return "Please enter a valid date as YYYY-MM-DD";
134 if (wo.content==null || wo.content=='')
135 return "Please enter content for the event.";
140 $scope.saveNew = function() {
141 $scope.newWidgetObject.category = message.type;
142 // $log.info($scope.newWidgetObject);
143 var validateMsg = $scope.validateWidgetObject($scope.newWidgetObject);
145 confirmBoxService.showInformation(validateMsg).then(isConfirmed => {return;});
148 // Transform date into expected storage format
149 $scope.newWidgetObject.eventDate = $filter('date')($scope.newWidgetObject.eventDate, "yyyy-MM-dd");
151 dashboardService.saveCommonWidgetData($scope.newWidgetObject)
153 if (res.status == 'OK') {
154 confirmBoxService.showInformation('You have added a new item').then(isConfirmed => {
156 dashboardService.getCommonWidgetData(message.type)
158 $scope.widgetData = res.response.items;
159 $scope.newWidgetObject = {};
163 confirmBoxService.showInformation("Save failed").then(isConfirmed => {return;});
169 $scope.remove = function(index) {
170 var confirmMsg = 'Are you sure you want to delete this item from the list?' + ' Press OK to delete.';
171 confirmBoxService.confirm(confirmMsg).then(function (confirmed) {
172 if (confirmed == true) {
173 $scope.widgetObject = {};
174 $scope.widgetObject.id = $scope.widgetData[parseInt(index)].id;
175 $scope.widgetObject.category = $scope.widgetData[parseInt(index)].category;
176 $scope.widgetObject.title = $scope.widgetData[parseInt(index)].title;
177 $scope.widgetObject.href = $scope.widgetData[parseInt(index)].href;
178 $scope.widgetObject.sortOrder = $scope.widgetData[parseInt(index)].sortOrder;
181 dashboardService.removeCommonWidgetData($scope.widgetObject)
183 dashboardService.getCommonWidgetData(message.type)
185 $scope.widgetData = res.response.items;
186 $scope.cancelEdit(index);
193 $scope.closeDialog = function(){
194 $scope.closeThisDialog( $scope.widgetData);
196 $scope.deleteSpeedDial = function(widget){
200 $scope.manage = function(index) {
201 $scope.modflag = true;
203 var thisdata = $scope.widgetData[index];
204 $scope.editMode=true;
205 var category = "#category"+index;
206 var categoryEdit = "#categoryEdit"+index;
208 var title = "#title"+index;
209 var titleEdit = "#titleEdit"+index;
211 var url = "#href"+index;
212 var urlEdit = "#hrefEdit"+index;
214 var order = "#order"+index;
215 var orderEdit = "#orderEdit"+index;
217 var eventDate = "#eventDate"+index;
218 var eventDateEdit = "#eventDateEdit"+index;
221 var dsavebutton ="#savebutton"+index;
222 var dremovebutton="#removebutton"+index;
223 var dmanagebutton="#managebutton"+index;
224 var deditRbutton="#editRbutton"+index;
226 $(title).css('display', 'none');
227 $(titleEdit).css('display', 'inherit');
228 $(url).css('display', 'none');
229 $(urlEdit).css('display', 'inherit');
230 $(order).css('display', 'none');
231 $(orderEdit).css('display', 'inherit');
232 $(eventDate).css('display', 'none');
233 $(eventDateEdit).css('display', 'inherit');
235 $(dsavebutton).css('display', 'inherit');
236 $(dremovebutton).css('display', 'inherit');
237 $(dmanagebutton).css('display', 'none');
238 $(deditRbutton).css('display', 'inherit');
242 $scope.cancelEdit = function(index) {
244 $scope.editMode=false;
245 var category = "#category"+index;
246 var categoryEdit = "#categoryEdit"+index;
248 var title = "#title"+index;
249 var titleEdit = "#titleEdit"+index;
251 var url = "#href"+index;
252 var urlEdit = "#hrefEdit"+index;
254 var order = "#order"+index;
255 var orderEdit = "#orderEdit"+index;
257 var eventDate = "#eventDate"+index;
258 var eventDateEdit = "#eventDateEdit"+index;
260 var dsavebutton ="#savebutton"+index;
261 var dremovebutton ="#removebutton"+index;
262 var dmanagebutton="#managebutton"+index;
263 var deditRbutton="#editRbutton"+index;
265 $(title).css('display', 'inherit');
266 $(titleEdit).css('display', 'none');
268 $(url).css('display', 'inherit');
269 $(urlEdit).css('display', 'none');
271 $(order).css('display', 'inherit');
272 $(orderEdit).css('display', 'none');
274 $(eventDate).css('display', 'inherit');
275 $(eventDateEdit).css('display', 'none');
277 $(dsavebutton).css('display', 'none');
278 $(dremovebutton).css('display', 'none');
279 $(dmanagebutton).css('display', 'inherit');
280 $(deditRbutton).css('display', 'none');
284 $scope.popupConfirmWin = function(title, msgBody, callback){
285 modalService.popupConfirmWin.apply(null, arguments);
289 CommonWidgetController.$inject = ['dashboardService', '$scope', 'message', '$q', '$http', 'conf', '$filter','confirmBoxService','$log'];
290 angular.module('ecompApp').controller('CommonWidgetController', CommonWidgetController);
293 angular.module('ecompApp').filter('cut', function () {
294 return function (value, wordwise, max, tail) {
295 if (!value) return '';
297 max = parseInt(max, 10);
298 if (!max) return value;
299 if (value.length <= max) return value;
301 value = value.substr(0, max);
303 var lastspace = value.lastIndexOf(' ');
304 if (lastspace != -1) {
305 //Also remove . and , so its gives a cleaner result.
306 if (value.charAt(lastspace-1) == '.' || value.charAt(lastspace-1) == ',') {
307 lastspace = lastspace - 1;
309 value = value.substr(0, lastspace);
313 return value + (tail || ' …');
317 angular.module('ecompApp').controller('DatePickerController', function ($scope, uibDateParser) {
318 $scope.today = function() {
319 $scope.dt = new Date();
323 $scope.clear = function() {
327 $scope.inlineOptions = {
328 customClass: getDayClass,
333 $scope.dateOptions = {
334 dateDisabled: disabled,
340 // Disable weekend selection
341 function disabled(data) {
342 var date = data.date,
344 return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
347 $scope.toggleMin = function() {
348 $scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null : new Date();
349 $scope.dateOptions.minDate = $scope.inlineOptions.minDate;
354 $scope.open1 = function() {
355 // console.log('In open1');
356 $scope.popup1.opened = true;
359 $scope.open2 = function() {
360 // console.log('In open2');
361 $scope.popup2.opened = true;
365 $scope.setDate = function(year, month, day) {
366 $scope.dt = new Date(year, month, day);
369 $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
370 $scope.format = $scope.formats[3];
371 $scope.altInputFormats = ['M!/d!/yyyy'];
381 var tomorrow = new Date();
382 tomorrow.setDate(tomorrow.getDate() + 1);
383 var afterTomorrow = new Date();
384 afterTomorrow.setDate(tomorrow.getDate() + 1);
396 function getDayClass(data) {
397 var date = data.date,
399 if (mode === 'day') {
400 var dayToCheck = new Date(date).setHours(0,0,0,0);
402 for (var i = 0; i < $scope.events.length; i++) {
403 var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
405 if (dayToCheck === currentDay) {
406 return $scope.events[i].status;
417 function toggleCollapsible(id, clickedIconId, subtitutingIconId){
419 $("#"+clickedIconId).toggle();
420 $("#"+subtitutingIconId).toggle();
421 setTimeout(function(){focusFirstEle(id);}, 1000);
424 function focusFirstEle(id){
425 var focusItems = $("#"+id).find(":focusable");
426 for(var i=0; i<focusItems.length; i++){
427 if(!isHidden(focusItems[i])){
428 var targetClassName = focusItems[i].className;
429 if(targetClassName!='collapsibleArrow'){
430 focusItems[i].focus();
437 function validateUrl(value){
438 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])\.(\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]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);