summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-widget-ms/common-widgets/news-widget/js/controller.js
blob: 131333393ebd28f4f099c3973f5884c07f06ed1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function NewsCtrl($rootScope, applicationsService , $log,
			$window, userProfileService, $scope, $cookies, $timeout, $interval,
			$uibModal, dashboardService, ngDialog) {
		
		var _this = this;	

		//activate spinner
		this.isLoading = true;
		$scope.getUserAppsIsDone = false;
		this.userProfileService = userProfileService;
		$scope.demoNum = 1;
		$scope.event_content_show = false;
		$scope.widgetData = [];

		$scope.editWidgetModalPopup = function(availableData, resourceType) {

			$scope.editData = JSON.stringify(availableData);
			$scope.availableDataTemp = $scope.availableData;
			ngDialog.open({
						templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
						controller : 'CommonWidgetController',
						resolve : {
							message : function message() {
								var message = {
									type : resourceType,
									availableData : $scope.editData
								};
								return message;
							}
						}
					}).closePromise.then(needUpdate => {	
						if(resourceType=='NEWS'){
							$scope.updateNews();
						}else if(resourceType=='EVENTS'){
							$scope.updateEvents();
						}else if(resourceType=='IMPORTANTRESOURCES'){
							$scope.updateImportRes();
						}
	                });		
		};
		
		/*Setting News data*/
		$scope.newsData = [];
		$scope.updateNews = function() {
			$scope.newsData.length=0;
			//dashboardService.getCommonWidgetData('NEWS').then(function(res) {
				// $log.info(res.message);
				var newsDataJsonArray = res.response.items;
				for (var i = 0; i < newsDataJsonArray.length; i++) {
					$scope.newsData.push(newsDataJsonArray[i]);
				}
			//})['catch'](function(err) {
			//	$log.error('dashboard controller: failed to get news list', err);
			//	_this.isLoading = false;
			//});
		}
		$scope.updateNews();

	}