1
0

nightly commit

This commit is contained in:
2021-02-03 16:08:40 +08:00
parent 0eeea13277
commit 809b32c051
20 changed files with 471 additions and 197 deletions

View File

@@ -406,14 +406,18 @@ function ccn_api_admin_add(_username) {
}
function ccn_api_admin_update(_username, _password, _isAdmin) {
return ccn_api_dataTemplate(
var data = {};
if (typeof(_password) != 'undefined')
data.password = _password;
if (typeof(_isAdmin) != 'undefined')
data.isAdmin = _isAdmin;
if (Object.getOwnPropertyNames(data).length == 0) return false;
data.token = GetApiToken();
data.username = _username;
return ccn_api_boolTemplate(
'/api/admin/update',
{
token: GetApiToken(),
username: _username,
password: _password,
isAdmin: _isAdmin
}
data
);
}

View File

@@ -29,6 +29,7 @@ function ccn_headerNav_BindEvents() {
$("#ccn-header-language > *").each(function(){
$(this).click(function(){
ccn_i18n_ChangeLanguage($(this).attr("language"));
ccn_i18n_LoadLanguage();
ccn_i18n_ApplyLanguage();
});
});

View File

@@ -23,41 +23,48 @@ function ccn_i18n_ChangeLanguage(newLang) {
return true;
}
function ccn_i18n_ApplyLanguage() {
function ccn_i18n_LoadLanguage() {
$.i18n.properties({
name: 'strings_' + ccn_i18n_currentLanguage,
path: '/static/i18n/',
encoding: 'utf-8',
mode: 'map',
async: true,
async: false,
cache: false,
language: ccn_i18n_currentLanguage,
callback: function() {
//set usual block
var cache = $("[i18n-name]");
cache.each(function() {
$(this).html($.i18n.prop($(this).attr('i18n-name')));
});
//set unusual block
//set title
switch(ccn_pages_currentPage) {
case ccn_pages_enumPages.home:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-home'));
break;
case ccn_pages_enumPages.calendar:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-calendar'));
break;
case ccn_pages_enumPages.todo:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-todo'));
break;
case ccn_pages_enumPages.admin:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-admin'));
break;
case ccn_pages_enumPages.login:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-login'));
break;
}
}
language: ccn_i18n_currentLanguage
});
}
function ccn_i18n_ApplyLanguage() {
//set usual block
var cache = $("[i18n-name]");
cache.each(function() {
$(this).html($.i18n.prop($(this).attr('i18n-name')));
});
//set unusual block
//set title
switch(ccn_pages_currentPage) {
case ccn_pages_enumPages.home:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-home'));
break;
case ccn_pages_enumPages.calendar:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-calendar'));
break;
case ccn_pages_enumPages.todo:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-todo'));
break;
case ccn_pages_enumPages.admin:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-admin'));
break;
case ccn_pages_enumPages.login:
$('#ccn-pageName').html($.i18n.prop('ccn-pageName-login'));
break;
}
}
function ccn_i18n_ApplyLanguage2Content(ctx) {
ctx.find("[i18n-name]").each(function() {
$(this).html($.i18n.prop($(this).attr('i18n-name')));
});
}

View File

@@ -1,3 +1,5 @@
var ccn_admin_userListCache = [];
$(document).ready(function() {
ccn_pages_currentPage = ccn_pages_enumPages.admin;
@@ -13,6 +15,191 @@ $(document).ready(function() {
ccn_messagebox_Insert();
ccn_messagebox_BindEvent();
// bind tab control switcher and set current tab
$("#tabcontrol-tab-1-1").click(function(){
ccn_tabcontrol_SwitchTab(1, 1);
});
$("#tabcontrol-tab-1-2").click(function(){
ccn_tabcontrol_SwitchTab(1, 2);
});
ccn_tabcontrol_SwitchTab(1, 1);
// load user tab according to admin status
if(!ccn_api_common_isAdmin())
$('#tabcontrol-tab-1-2').hide();
// apply i18n
ccn_i18n_LoadLanguage();
ccn_i18n_ApplyLanguage();
});
// bind event
$('#ccn-admin-profile-btnChangePassword').click(ccn_admin_profile_ChangePassword);
$('#ccn-admin-userList-btnAdd').click(ccn_admin_userList_Add);
$('#ccn-admin-userList-btnRefresh').click(ccn_admin_userList_Refresh);
});
// ================== profile
function ccn_admin_profile_ChangePassword() {
var newpassword = $('#ccn-admin-profile-inputPassword').val();
if (newpassword == "") return;
var result = ccn_api_common_changePassword(newpassword);
if(result) {
ccn_messagebox_Show($.i18n.prop("ccn-js-success"));
$('#ccn-admin-profile-inputPassword').val('');
} else
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-update"));
}
// ================== user list
function ccn_admin_userList_RefreshCacheList() {
ccn_admin_userListCache = new Array();
var result = ccn_api_admin_get();
if(typeof(result) != 'undefined') {
for(var index in result) {
ccn_admin_userListCache[index] = result[index];
}
}
}
function ccn_admin_userList_RenderItem(item, index, listDOM, renderdata) {
var renderdata = {
uuid: index, // use index for uuid. there are no uuid for user
username: item[0]
}
// render
listDOM.append(ccn_template_userItem.render(renderdata));
// set mode
var uuid = index;
ccn_admin_userList_ChangeDisplayMode(uuid, false, item[1])
// bind event
$("#ccn-admin-userItem-btnEdit-" + uuid).click(ccn_admin_userList_ItemEdit);
$("#ccn-admin-userItem-btnDelete-" + uuid).click(ccn_admin_userList_ItemDelete);
$("#ccn-admin-userItem-btnUpdate-" + uuid).click(ccn_admin_userList_ItemUpdate);
$("#ccn-admin-userItem-btnCancelUpdate-" + uuid).click(ccn_admin_userList_ItemCancelUpdate);
}
function ccn_admin_userList_RenderCacheList() {
$('#ccn-admin-userList').empty();
var listDOM = $('#ccn-admin-userList');
for(var index in ccn_admin_userListCache) {
ccn_admin_userList_RenderItem(
ccn_admin_userListCache[index],
index,
listDOM
)
}
ccn_i18n_ApplyLanguage2Content(listDOM);
}
function ccn_admin_userList_ChangeDisplayMode(uuid, isEdit, isAdmin) {
if (typeof(isAdmin) != 'undefined') {
if (isAdmin)
$("#ccn-admin-userItem-iconIsAdmin-" + uuid).show();
else
$("#ccn-admin-userItem-iconIsAdmin-" + uuid).hide();
}
if (typeof(isEdit) != 'undefined') {
if (isEdit) {
$("#ccn-admin-userItem-btnEdit-" + uuid).hide();
$("#ccn-admin-userItem-btnDelete-" + uuid).hide();
$("#ccn-admin-userItem-btnUpdate-" + uuid).show();
$("#ccn-admin-userItem-btnCancelUpdate-" + uuid).show();
$("#ccn-admin-userItem-boxPassword-" + uuid).show();
$("#ccn-admin-userItem-boxIsAdmin-" + uuid).show();
} else {
$("#ccn-admin-userItem-btnEdit-" + uuid).show();
$("#ccn-admin-userItem-btnDelete-" + uuid).show();
$("#ccn-admin-userItem-btnUpdate-" + uuid).hide();
$("#ccn-admin-userItem-btnCancelUpdate-" + uuid).hide();
$("#ccn-admin-userItem-boxPassword-" + uuid).hide();
$("#ccn-admin-userItem-boxIsAdmin-" + uuid).hide();
}
}
}
function ccn_admin_userList_Refresh() {
// refresh and render once
ccn_admin_userList_RefreshCacheList();
ccn_admin_userList_RenderCacheList();
}
function ccn_admin_userList_Add() {
var username = $('#ccn-admin-userList-inputUsername').val();
if (username == "") return;
var result = ccn_api_admin_add(username);
if (typeof(result) == 'undefined') {
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-add"));
} else {
// render
var index = ccn_admin_userListCache.push(result) - 1;
var listDOM = $('#ccn-admin-userList');
ccn_admin_userList_RenderItem(result, index, listDOM);
ccn_i18n_ApplyLanguage2Content(listDOM);
}
}
function ccn_admin_userList_ItemEdit() {
var uuid = $(this).attr("uuid");
// copy isAdmin to checkbox and clean password box
$('#ccn-admin-userItem-inputIsAdmin-' + uuid).prop("checked", ccn_admin_userListCache[uuid][1]);
$('#ccn-admin-userItem-inputPassword-' + uuid).val('');
// switch to edit mode
ccn_admin_userList_ChangeDisplayMode(uuid, true, undefined);
}
function ccn_admin_userList_ItemDelete() {
var uuid = $(this).attr("uuid");
var result = ccn_api_admin_delete(ccn_admin_userListCache[uuid][0]);
if(!result) {
// fail
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-delete"));
} else {
// remove body
$("#ccn-admin-userItem-" + uuid).remove();
}
}
function ccn_admin_userList_ItemUpdate() {
var uuid = $(this).attr("uuid");
var newpassword = $('#ccn-admin-userItem-inputPassword-' + uuid).val();
var isAdmin = $('#ccn-admin-userItem-inputIsAdmin-' + uuid).prop("checked");
var result = ccn_api_admin_update(
ccn_admin_userListCache[uuid][0],
newpassword == "" ? undefined : newpassword,
isAdmin == ccn_admin_userListCache[uuid][1] ? undefined : isAdmin);
if (!result) {
// fail
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-update"));
} else {
// safely update data
ccn_admin_userListCache[uuid][1] = isAdmin
// switch to normal mode
ccn_admin_userList_ChangeDisplayMode(uuid, false, isAdmin);
}
}
function ccn_admin_userList_ItemCancelUpdate() {
var uuid = $(this).attr("uuid");
ccn_admin_userList_ChangeDisplayMode(uuid, false, undefined);
}

View File

@@ -1,3 +1,7 @@
var ccn_calendar_sharingListCache = [];
var ccn_calendar_sharingTargetListCache = [];
var ccn_calendar_sharedListCache = [];
$(document).ready(function() {
ccn_pages_currentPage = ccn_pages_enumPages.calendar;
@@ -29,9 +33,54 @@ $(document).ready(function() {
ccn_tabcontrol_SwitchTab(1, 1);
// apply i18n
ccn_i18n_LoadLanguage();
ccn_i18n_ApplyLanguage();
});
function ccn_calendar_LoadCalendarBody() {
$('#ccn-calendar-calendarBbody').append(ccn_template_calendarItem.render());
}
// ================== calendar
// ================== collection
function ccn_calendar_sharing_Refresh() {
ccn_calendar_sharingListCache = new Array();
var result = ccn_api_collection_getFullOwn();
if(typeof(result) != 'undefined') {
for(var index in result) {
ccn_calendar_sharingListCache[result[index][0]] = result[index];
}
}
// render
$('#ccn-admin-userList').empty();
var listDOM = $('#ccn-admin-userList');
for(var index in ccn_admin_userListCache) {
ccn_admin_userList_RenderItem(
ccn_admin_userListCache[index],
index,
listDOM
)
}
}
function ccn_calendar_sharing_RenderItem() {
}
function ccn_calendar_sharingTarget_Refresh() {
}
function ccn_calendar_sharingTarget_RenderItem() {
}
function ccn_calendar_shared_Refresh() {
}

View File

@@ -14,5 +14,6 @@ $(document).ready(function() {
ccn_messagebox_BindEvent();
// apply i18n
ccn_i18n_LoadLanguage();
ccn_i18n_ApplyLanguage();
});

View File

@@ -14,6 +14,7 @@ $(document).ready(function() {
ccn_messagebox_BindEvent();
// apply i18n
ccn_i18n_LoadLanguage();
ccn_i18n_ApplyLanguage();
// bind login event

View File

@@ -16,6 +16,7 @@ $(document).ready(function() {
ccn_messagebox_BindEvent();
// apply i18n
ccn_i18n_LoadLanguage();
ccn_i18n_ApplyLanguage();
// refresh once
@@ -103,7 +104,7 @@ function ccn_todo_Add() {
var result = ccn_api_todo_add();
if (typeof(result) == 'undefined') {
// fail
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-operate"));
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-add"));
} else {
// add into cache
ccn_todo_todoListCache[result[0]] = result;
@@ -147,9 +148,9 @@ function ccn_todo_ItemDelete() {
ccn_todo_todoListCache[uuid][3]
);
if(typeof(result) == 'undefined') {
if(!result) {
// fail
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-operate"));
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-delete"));
} else {
// remove body
$("#ccn-todo-todoItem-" + uuid).remove();
@@ -168,7 +169,7 @@ function ccn_todo_ItemUpdate() {
if (typeof(result) == 'undefined') {
// fail
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-operate"));
ccn_messagebox_Show($.i18n.prop("ccn-js-fail-update"));
} else {
// safely update data & lastChanged and control
ccn_todo_todoListCache[uuid][2] = newData;

View File

@@ -2,6 +2,9 @@ var ccn_template_headerNav = undefined;
var ccn_template_messagebox = undefined;
var ccn_template_calendarItem = undefined;
var ccn_template_scheduleItem = undefined;
var ccn_template_sharingItem = undefined;
var ccn_template_sharingTargetItem = undefined;
var ccn_template_sharedItem = undefined;
var ccn_template_userItem = undefined;
var ccn_template_todoItem = undefined;
@@ -43,6 +46,30 @@ function ccn_template_Load() {
ccn_template_scheduleItem = $.templates(data);
}
});
$.ajax({
url: $("#jsrender-tmpl-sharingItem").attr('src'),
type: "GET",
async: false,
success: function (data) {
ccn_template_sharingItem = $.templates(data);
}
});
$.ajax({
url: $("#jsrender-tmpl-sharingTargetItem").attr('src'),
type: "GET",
async: false,
success: function (data) {
ccn_template_scheduleItem = $.templates(data);
}
});
$.ajax({
url: $("#jsrender-tmpl-sharedItem").attr('src'),
type: "GET",
async: false,
success: function (data) {
ccn_template_scheduleItem = $.templates(data);
}
});
break;
case ccn_pages_enumPages.todo:
$.ajax({