sheercms
Version:
Sheer Cliff CMS is a simple and powerful content management system (CMS) for Node JS.
97 lines (74 loc) • 2.36 kB
JavaScript
var IconSelectorController = function ($scope, $q, $modalInstance, IconService, value, title) {
$scope.dialog = {
title: "",
message: "",
messageType: "",
disableOk: true
};
$scope.data = {
allIcons: [],
pageIcons: [],
selectedIcon: null
};
$scope.paging = {
pageSize: 100,
pageNum: 1,
pageCount: 0,
paginate: function(num) {
loadIcons(num);
}
};
$scope.ok = function () {
if ($scope.data.selectedIcon !== null) {
var url = $scope.data.selectedIcon.url;
$modalInstance.close(url);
}
else {
$modalInstance.close(null);
}
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
$scope.selectItem = function(item) {
$scope.data.selectedIcon = item;
};
function loadIcons(pageNumber) {
$scope.paging.pageNum = pageNumber;
var start = (pageNumber - 1) * $scope.paging.pageSize;
var end = (start + $scope.paging.pageSize > $scope.data.allIcons.length) ? $scope.data.allIcons.length - 1 : start + $scope.paging.pageSize;
var arr = [];
for(var i = start; i < end; i++) {
arr.push($scope.data.allIcons[i]);
}
$scope.data.pageIcons = arr;
}
function loadAllIcons() {
IconService.getIcons().then(function(result) {
setMessage(result.message, result.success == true ? "alert-success" : "alert-danger");
if (result.success && result.icons) {
$scope.data.allIcons = result.icons;
//set the paging data
$scope.paging.pageCount = Math.ceil(result.icons.length / $scope.paging.pageSize);
}
else
$scope.data.allIcons = [];
loadIcons(1); //load first page of icons
});
};
function clearMessage() {
$scope.dialog.message = "";
$scope.dialog.messageType = "";
}
function setMessage(msg, type) {
$scope.dialog.message = msg;
$scope.dialog.messageType = type;
}
function init()
{
$scope.dialog.title = title || "Icon Selector";
$scope.data.selectionIcon = null;
loadAllIcons();
}
init();
};