Light12306/ChatRoomServer.Www/Scripts/controller.js

314 lines
8.0 KiB
JavaScript
Raw Normal View History

2015-07-13 21:18:04 +08:00
'use strict';
var app = angular.module('chat12306', ['ngCookies']);
2015-07-10 21:32:52 +08:00
2015-07-13 21:18:04 +08:00
(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;
};
});
2015-07-15 20:55:09 +08:00
app.filter('jsonDate', function () {
return function (input) {
var data = /^(\d{4}-\d{2}-\d{2})T([\d\:]+)/i.exec(input || "");
return data && String.format("{0} {1}", data[1], data[2]) || input;
};
});
app.filter('abuseStatusDesc', function () {
return function (input) {
return ["未处理", "已处理", "已忽略", "已自动处理"][parseInt(input)];
};
});
2015-07-13 21:18:04 +08:00
app.filter('pagelist', function () {
return function (current, max, pagePerSide) {
max = parseInt(max);
current = parseInt(current);
pagePerSide = parseInt(pagePerSide) || 4;
var result = [];
2015-07-15 20:55:09 +08:00
for (var i = 1; i <= pagePerSide + 1 && i <= max; i++) {
result.push(i);
2015-07-13 21:18:04 +08:00
}
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);
2015-07-15 20:55:09 +08:00
for (var k = max - pagePerSide; k >= 1 && k <= max; k++) {
2015-07-13 21:18:04 +08:00
result.push(k);
}
2015-07-10 21:32:52 +08:00
2015-07-13 21:18:04 +08:00
return result;
};
});
})();
(function () {
app.controller('AccountLogin', accountLoginController);
accountLoginController.$inject = ['$scope', '$cookies', '$cookieStore', '$http', '$location'];
2015-07-10 21:32:52 +08:00
2015-07-13 21:18:04 +08:00
function accountLoginController($scope, $cookies, $cookieStore, $http, $location) {
2015-07-10 21:32:52 +08:00
$scope.operating = false;
$scope.user = {
password: ""
};
$scope.login = function () {
2015-07-13 21:18:04 +08:00
var notify = $.notify({
title: "登录中...",
message: "正在登录中,请稍等...",
"icon": "fa-spin fa fa-spinner"
}, {
2015-07-10 21:32:52 +08:00
delay: 0,
progress: -1,
showProgressbar: true,
2015-07-13 21:18:04 +08:00
allow_dismiss: false,
placement: {
from: "top",
align: "center"
}
2015-07-10 21:32:52 +08:00
});
$scope.operating = true;
2015-07-13 21:18:04 +08:00
$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'];
2015-07-15 20:55:09 +08:00
var controlApi = "/api/users/updateAbuseReport";
2015-07-13 21:18:04 +08:00
$scope.filters = [{ typeid: -1, title: "所有" }, { typeid: 0, title: "未处理" }, { typeid: 1, title: "已处理" }, { typeid: 2, title: "已忽略" }, { typeid: 3, title: "已自动处理" }];
$scope.filterid = -1;
$scope.items = [{ title: "test" }];
2015-07-15 20:55:09 +08:00
$scope.pages = 0;
2015-07-13 21:18:04 +08:00
$scope.pageSize = 50;
$scope.itemsCount = 0;
$scope.pageIndex = 1;
$scope.ignore = function (index) {
};
$scope.blockTarget = function (code) {
};
$scope.blockSource = function (code) {
2015-07-10 21:32:52 +08:00
};
2015-07-13 21:18:04 +08:00
var load = function () {
var notify = $.notify({
title: "正在加载数据,请稍等...",
message: "",
"icon": "fa-spin fa fa-spinner",
type: "info"
}, {
delay: 0,
progress: -1,
2015-07-15 20:55:09 +08:00
showProgressbar: true,
2015-07-13 21:18:04 +08:00
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
});
2015-07-15 20:55:09 +08:00
notify.close();
2015-07-13 21:18:04 +08:00
$scope.items = data.items;
$scope.itemsCount = data.itemsCount || 0;
$scope.pages = Math.ceil($scope.itemsCount / $scope.pageSize);
}).error(function () {
notify.update({
"title": "加载失败,请重试。服务器错误啦....",
type: "danger",
2015-07-15 20:55:09 +08:00
icon: "fa fa-ban",
showProgressbar: false
2015-07-13 21:18:04 +08:00
});
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));
};
2015-07-15 20:55:09 +08:00
$scope.reload = function () {
load();
};
//操作
$scope.op = function (index, status) {
var item = $scope.items[index];
if (!confirm("确认操作?"))
return;
var notify = $.notify({
title: "操作中,请稍等...",
"icon": "fa-spin fa fa-spinner",
type: "info"
}, {
delay: 0,
progress: -1,
showProgressbar: true,
allow_dismiss: false,
placement: {
from: "top",
align: "center"
}
});
$http.post(controlApi, { id: item.id, status: status, bantime: item.bantime || "0" })
.success(function (data) {
if (data.success) {
notify.update({
"title": "操作成功...",
type: "success",
icon: "fa fa-check",
showProgressbar: false
});
} else {
notify.changeStatus("danger", "fa fa-ban", "操作失败:" + data.message, null, -2);
}
setTimeout(notify.close, 2000);
$("tr[data-id=" + item.id + "] button.btn").remove();
}).error(function () {
notify.setTitle("操作失败,请重试。服务器错误啦....").setType("danger").setIcon("fa fa-ban").hideProgress().delayClose();
});
};
2015-07-13 21:18:04 +08:00
$scope.$watch("filterid+pageIndex", function () {
load();
});
2015-07-10 21:32:52 +08:00
}
})();
2015-07-15 20:55:09 +08:00
(function chatMessageListControllerContainer() {
function chatMessageListController($scope, $http) {
var listApi = "/api/msgs/list";
$scope.filter = {
searchUser: "",
pageIndex: 1,
pagesize : "20"
};
$scope.pages = 0;
$scope.itemsCount = 0;
$scope.items = [];
//加载
$scope.reload = function () {
var notify = $.notify({
title: "数据加载中...",
"icon": "fa-spin fa fa-spinner",
type: "info"
}, {
delay: 0,
progress: -1,
showProgressbar: true,
allow_dismiss: false,
placement: {
from: "top",
align: "center"
}
});
$http.post(listApi, $scope.filter)
.success(function (data) {
if (data.success) {
notify.update({
"title": "操作成功...",
type: "success",
icon: "fa fa-check",
showProgressbar: false
});
$scope.items = data.items;
$scope.itemsCount = data.count;
} else {
notify.changeStatus("danger", "fa fa-ban", "加载失败:" + data.message, null, -2);
}
setTimeout(notify.close, 2000);
$("tr[data-id=" + item.id + "] button.btn").remove();
}).error(function () {
notify.setTitle("加载失败,请重试。服务器错误啦....").setType("danger").setIcon("fa fa-ban").hideProgress().delayClose();
});
};
$scope.goPage = function (page) {
if (page <= 0)
return;
$scope.filter.pageIndex = page;
};
$scope.go = function (pageOffset) {
$scope.filter.pageIndex = Math.max(1, Math.min($scope.filter.pageIndex + pageOffset, $scope.pages));
};
$scope.$watch("filter", function (newvalue, oldvalue) {
$scope.reload();
}, true);
}
app.controller("ChatMessageListController", ['$scope', '$http', chatMessageListController]);
})();