Light12306/ChatRoomServer.Www/Scripts/controller.js
2015-07-13 21:18:04 +08:00

193 lines
4.7 KiB
JavaScript

'use strict';
var app = angular.module('chat12306', ['ngCookies']);
(function filters() {
app.filter('range', function () {
return function (input, total) {
total = parseInt(total);
for (var i = 0; i < total; i++)
input.push(i);
return input;
};
});
app.filter('pagelist', function () {
return function (current, max, pagePerSide) {
max = parseInt(max);
current = parseInt(current);
pagePerSide = parseInt(pagePerSide) || 4;
var result = [];
for (var i = 1; i <= pagePerSide + 1; i++) {
if (i < max)
result.push(i);
}
if (current - pagePerSide > pagePerSide + 1 + 1) {
result.push(-1);
}
for (var j = current - pagePerSide; j <= current + pagePerSide; j++) {
if (j <= pagePerSide + 1 || j > max - pagePerSide + 1)
continue;
result.push(j);
}
if (max - pagePerSide > current + pagePerSide + 1)
result.push(-2);
for (var k = max - pagePerSide; k <= max; k++) {
result.push(k);
}
return result;
};
});
})();
(function () {
app.controller('AccountLogin', accountLoginController);
accountLoginController.$inject = ['$scope', '$cookies', '$cookieStore', '$http', '$location'];
function accountLoginController($scope, $cookies, $cookieStore, $http, $location) {
$scope.operating = false;
$scope.user = {
password: ""
};
$scope.login = function () {
var notify = $.notify({
title: "登录中...",
message: "正在登录中,请稍等...",
"icon": "fa-spin fa fa-spinner"
}, {
delay: 0,
progress: -1,
showProgressbar: true,
allow_dismiss: false,
placement: {
from: "top",
align: "center"
}
});
$scope.operating = true;
$http.post("/api/account/login", $scope.user)
.success(function (data) {
if (data.success) {
notify.update({
"message": "登录成功!",
icon: "fa fa-check",
type: "success",
showProgressbar: false
});
setTimeout(function () {
self.location = "/";
}, 2000);
} else {
notify.update({
"message": "登录失败:" + data.message,
icon: "fa fa-ban",
type: "danger",
showProgressbar: false
});
setTimeout(notify.close, 2000);
}
$scope.operating = false;
}).error(function () {
notify.update({
"message": "登录失败,请重试。服务器错误啦....",
type: "danger",
icon: "fa fa-ban",
showProgressbar: false,
placement: ""
});
setTimeout(notify.close, 2000);
$scope.operating = false;
});
};
}
})();
(function abuseListControllerContainer() {
app.controller("AbuseListController", abuseListController);
function abuseListController($scope, $http) {
abuseListController.$inject = ['$scope', '$http'];
$scope.filters = [{ typeid: -1, title: "所有" }, { typeid: 0, title: "未处理" }, { typeid: 1, title: "已处理" }, { typeid: 2, title: "已忽略" }, { typeid: 3, title: "已自动处理" }];
$scope.filterid = -1;
$scope.items = [{ title: "test" }];
$scope.pages = 20;
$scope.pageSize = 50;
$scope.itemsCount = 0;
$scope.pageIndex = 1;
$scope.ignore = function (index) {
};
$scope.blockTarget = function (code) {
};
$scope.blockSource = function (code) {
};
var load = function () {
var notify = $.notify({
title: "正在加载数据,请稍等...",
message: "",
"icon": "fa-spin fa fa-spinner",
type: "info"
}, {
delay: 0,
progress: -1,
showProgressbar: false,
allow_dismiss: false,
placement: {
from: "top",
align: "center"
}
});
$http.post("/api/users/abuseList", { pageSize: $scope.pageSize, pageIndex: $scope.pageIndex, filter: $scope.filterid })
.success(function (data) {
notify.update({
"title": "加载成功...",
type: "success",
icon: "fa fa-check",
showProgressbar: false
});
setTimeout(notify.close, 2000);
$scope.items = data.items;
$scope.itemsCount = data.itemsCount || 0;
$scope.pages = Math.ceil($scope.itemsCount / $scope.pageSize);
}).error(function () {
notify.update({
"title": "加载失败,请重试。服务器错误啦....",
type: "danger",
icon:"fa fa-ban",
showProgressbar: false,
placement: ""
});
setTimeout(notify.close, 2000);
$scope.items = [];
});
setTimeout(notify.close, 2000);
};
//重设过滤器
$scope.resetFilter = function (id) {
$scope.filterid = id;
};
$scope.goPage = function (page) {
if (page <= 0)
return;
$scope.pageIndex = page;
};
$scope.go = function (pageOffset) {
$scope.pageIndex = Math.max(1, Math.min($scope.pageIndex + pageOffset, $scope.pages));
};
$scope.$watch("filterid+pageIndex", function () {
load();
});
}
})();