All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template-application-angular.ui.perspectives.views.list.controller.js.template Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
#set($dollar = '$' )
angular.module('page', []);
angular.module('page')
.factory('httpRequestInterceptor', function () {
	return {
		request: function (config) {
			config.headers['X-Requested-With'] = 'Fetch';
			return config;
		}
	};
})
.config(['$httpProvider', function($httpProvider) {
	$httpProvider.interceptors.push('httpRequestInterceptor');
}])
.factory('$messageHub', [function(){
	var messageHub = new FramesMessageHub();

	var message = function(evtName, data){
#if($includeLaunchpad)
		messageHub.post({data: data}, '${projectName}.${perspectiveName}.${name}.' + evtName);
#else
		messageHub.post({data: data}, '${launchpadName}.${perspectiveName}.${name}.' + evtName);
#end
	};

	var on = function(topic, callback){
		messageHub.subscribe(callback, topic);
	};

	return {
		message: message,
		on: on,
		onEntityRefresh: function(callback) {
#if($includeLaunchpad)
			on('${projectName}.${perspectiveName}.${name}.refresh', callback);
#else
			on('${launchpadName}.${perspectiveName}.${name}.refresh', callback);
#end
		},
#foreach ($property in $properties)
#if($property.widgetType == "DROPDOWN" && $property.relationshipEntityName != "")
		on${property.relationshipEntityName}Modified: function(callback) {
#if($includeLaunchpad)
			on('${projectName}.${perspectiveName}.${property.relationshipEntityName}.modified', callback);
#else
			on('${launchpadName}.${perspectiveName}.${property.relationshipEntityName}.modified', callback);
#end
		},
#end
#end
		messageEntityModified: function() {
			message('modified');
		}
	};
}])
.controller('PageController', function ($scope, $http, $messageHub) {

	var api = '../../../../../../../../services/v3/js/${projectName}/api/${perspectiveName}/${name}.js';
#foreach ($property in $properties)
#if($property.widgetType == "DROPDOWN")
#if($property.widgetService && "$property.widgetService" != "")
	var ${property.name.toLowerCase()}OptionsApi = '${property.widgetService}';
#else
	var ${property.name.toLowerCase()}OptionsApi = '../../../../../../../../services/v3/js/${projectName}/api/${property.relationshipEntityPerspectiveName}/${property.relationshipEntityName}.js';
#end
#end
#end
#foreach ($property in $properties)
#if($property.widgetType == "DROPDOWN")

	$scope.${property.name.toLowerCase()}Options = [];
#end
#end

	$scope.dateOptions = {
		startingDay: 1
	};
	$scope.dateFormats = ['yyyy/MM/dd', 'dd-MMMM-yyyy', 'dd.MM.yyyy', 'shortDate'];
	$scope.dateFormat = $scope.dateFormats[0];
#foreach ($property in $properties)
#if($property.widgetType == "DROPDOWN")

	function ${property.name.toLowerCase()}OptionsLoad() {
		${dollar}http.get(${property.name.toLowerCase()}OptionsApi)
		.success(function(data) {
			$scope.${property.name.toLowerCase()}Options = data;
		});
	}
	${property.name.toLowerCase()}OptionsLoad();
#end
#end

	$scope.dataPage = 1;
	$scope.dataCount = 0;
	$scope.dataOffset = 0;
	$scope.dataLimit = 10;

	$scope.getPages = function() {
		return new Array($scope.dataPages);
	};

	$scope.nextPage = function() {
		if ($scope.dataPage < $scope.dataPages) {
			${dollar}scope.loadPage(${dollar}scope.dataPage + 1);
		}
	};

	$scope.previousPage = function() {
		if ($scope.dataPage > 1) {
			${dollar}scope.loadPage(${dollar}scope.dataPage - 1);
		}
	};

	$scope.loadPage = function(pageNumber) {
		$scope.dataPage = pageNumber;
		${dollar}http.get(api + '/count')
		.success(function(data) {
			$scope.dataCount = data;
			$scope.dataPages = Math.ceil($scope.dataCount / $scope.dataLimit);
			${dollar}http.get(api + '?${dollar}offset=' + ((pageNumber - 1) * ${dollar}scope.dataLimit) + '&${dollar}limit=' + ${dollar}scope.dataLimit)
			.success(function(data) {
				$scope.data = data;
			});
		});
	};
	$scope.loadPage($scope.dataPage);

	$scope.openInfoDialog = function(entity) {
		$scope.entity = entity;
		toggleEntityModal();
	};

	$scope.close = function() {
		$scope.loadPage($scope.dataPage);
		toggleEntityModal();
	};

#foreach ($property in $properties)
#if($property.widgetType == "DROPDOWN")
	${dollar}scope.${property.name.toLowerCase()}OptionValue = function(optionKey) {
		for (var i = 0 ; i < ${dollar}scope.${property.name.toLowerCase()}Options.length; i ++) {
			if (${dollar}scope.${property.name.toLowerCase()}Options[i].${property.widgetDropDownKey} === optionKey) {
				return ${dollar}scope.${property.name.toLowerCase()}Options[i].${property.widgetDropDownValue};
			}
		}
		return null;
	};
#end
#end

	$messageHub.onEntityRefresh($scope.loadPage($scope.dataPage));
#foreach ($property in $properties)
#if($property.widgetType == "DROPDOWN" && $property.relationshipEntityName != "")
	${dollar}messageHub.on${property.relationshipEntityName}Modified(${property.name.toLowerCase()}OptionsLoad);
#end
#end

	function toggleEntityModal() {
		$('#entityModal').modal('toggle');
	}
});




© 2015 - 2025 Weber Informatics LLC | Privacy Policy