refactor: introduce modern frontend
This commit is contained in:
265
frontend-legacy/static/js/page/admin.js
Normal file
265
frontend-legacy/static/js/page/admin.js
Normal file
@@ -0,0 +1,265 @@
|
||||
var ccn_admin_userListCache = [];
|
||||
var ccn_admin_tokenListCache = [];
|
||||
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.admin;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
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);
|
||||
});
|
||||
$("#tabcontrol-tab-1-3").click(function(){
|
||||
ccn_tabcontrol_SwitchTab(1, 3);
|
||||
});
|
||||
ccn_tabcontrol_SwitchTab(1, 1);
|
||||
|
||||
// load user tab according to admin status
|
||||
if(!ccn_api_profile_isAdmin())
|
||||
$('#tabcontrol-tab-1-3').hide();
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
|
||||
// bind event
|
||||
$('#ccn-admin-profile-btnChangePassword').click(ccn_admin_profile_ChangePassword);
|
||||
$('#ccn-admin-tokenList-btnRefresh').click(ccn_admin_tokenList_Refresh);
|
||||
$('#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_profile_changePassword(newpassword);
|
||||
if(result) {
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-success"));
|
||||
$('#ccn-admin-profile-inputPassword').val('');
|
||||
} else
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-update"));
|
||||
|
||||
}
|
||||
|
||||
// ================== token
|
||||
|
||||
function ccn_admin_tokenList_Refresh() {
|
||||
ccn_admin_tokenListCache = new Array();
|
||||
var listDOM = $('#ccn-admin-tokenList');
|
||||
listDOM.empty();
|
||||
|
||||
var renderdata = {
|
||||
uuid: undefined,
|
||||
isMe: undefined,
|
||||
ua: undefined,
|
||||
ip: undefined,
|
||||
expireOn: undefined
|
||||
}
|
||||
var gottenDateTime = new Date();
|
||||
|
||||
var result = ccn_api_profile_getToken();
|
||||
if(typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
var item = result[index];
|
||||
renderdata.uuid = item[1];
|
||||
renderdata.isMe = ccn_localstorageAssist_GetApiToken() == item[1];
|
||||
renderdata.ua = item[3];
|
||||
renderdata.ip = item[4];
|
||||
gottenDateTime.setTime(item[2] * 1000);
|
||||
renderdata.expireOn = gottenDateTime.toLocaleString();
|
||||
|
||||
listDOM.append(ccn_template_tokenItem.render(renderdata));
|
||||
|
||||
// bind event
|
||||
var uuid = renderdata.uuid;
|
||||
$("#ccn-tokenItem-btnLogout-" + uuid).click(ccn_admin_tokenList_ItemDelete);
|
||||
|
||||
// add into cache
|
||||
ccn_admin_tokenListCache[uuid] = item;
|
||||
}
|
||||
|
||||
ccn_i18n_ApplyLanguage2Content(listDOM);
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_admin_tokenList_ItemDelete() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
var result = ccn_api_profile_deleteToken(uuid);
|
||||
|
||||
if(!result) {
|
||||
// fail
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-delete"));
|
||||
} else {
|
||||
// remove body
|
||||
$("#ccn-tokenItem-" + uuid).remove();
|
||||
}
|
||||
}
|
||||
|
||||
// ================== 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) {
|
||||
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-userItem-btnEdit-" + uuid).click(ccn_admin_userList_ItemEdit);
|
||||
$("#ccn-userItem-btnDelete-" + uuid).click(ccn_admin_userList_ItemDelete);
|
||||
$("#ccn-userItem-btnUpdate-" + uuid).click(ccn_admin_userList_ItemUpdate);
|
||||
$("#ccn-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-userItem-iconIsAdmin-" + uuid).show();
|
||||
else
|
||||
$("#ccn-userItem-iconIsAdmin-" + uuid).hide();
|
||||
}
|
||||
|
||||
if (typeof(isEdit) != 'undefined') {
|
||||
if (isEdit) {
|
||||
$("#ccn-userItem-btnEdit-" + uuid).hide();
|
||||
$("#ccn-userItem-btnDelete-" + uuid).hide();
|
||||
$("#ccn-userItem-btnUpdate-" + uuid).show();
|
||||
$("#ccn-userItem-btnCancelUpdate-" + uuid).show();
|
||||
|
||||
$("#ccn-userItem-boxPassword-" + uuid).show();
|
||||
$("#ccn-userItem-boxIsAdmin-" + uuid).show();
|
||||
} else {
|
||||
$("#ccn-userItem-btnEdit-" + uuid).show();
|
||||
$("#ccn-userItem-btnDelete-" + uuid).show();
|
||||
$("#ccn-userItem-btnUpdate-" + uuid).hide();
|
||||
$("#ccn-userItem-btnCancelUpdate-" + uuid).hide();
|
||||
|
||||
$("#ccn-userItem-boxPassword-" + uuid).hide();
|
||||
$("#ccn-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-i18n-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-userItem-inputIsAdmin-' + uuid).prop("checked", ccn_admin_userListCache[uuid][1]);
|
||||
$('#ccn-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-i18n-js-fail-delete"));
|
||||
} else {
|
||||
// remove body
|
||||
$("#ccn-userItem-" + uuid).remove();
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_admin_userList_ItemUpdate() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
var newpassword = $('#ccn-userItem-inputPassword-' + uuid).val();
|
||||
var isAdmin = $('#ccn-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-i18n-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);
|
||||
}
|
||||
376
frontend-legacy/static/js/page/calendar.js
Normal file
376
frontend-legacy/static/js/page/calendar.js
Normal file
@@ -0,0 +1,376 @@
|
||||
// 2 list which will store sharing and shared collection's display mode.
|
||||
// key is uuid, value is bool
|
||||
var ccn_calendar_owned_displayCache = [];
|
||||
var ccn_calendar_shared_displayCache = [];
|
||||
|
||||
// modal editing object.
|
||||
// undefined mean add
|
||||
// not undefined mean update(a copy of calendar event)
|
||||
var ccn_calendar_eventModal_editing = undefined;
|
||||
var ccn_calendar_eventModal_collectionCache = [];
|
||||
var ccn_calendar_calendar_listCache = [];
|
||||
var ccn_calendar_calendar_displayCache = [];
|
||||
var ccn_calendar_calendar_displayDateTime = 0;
|
||||
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.calendar;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
ccn_messagebox_Insert();
|
||||
ccn_messagebox_BindEvent();
|
||||
|
||||
// process calendar it self
|
||||
ccn_calendar_calendar_LoadCalendarBody();
|
||||
|
||||
// init datetimepicker and preset
|
||||
ccn_datetimepicker_Insert();
|
||||
var nowtime = new Date();
|
||||
ccn_datetimepicker_Set(1, nowtime, false, ccn_datetimepicker_tabType.month);
|
||||
|
||||
// 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);
|
||||
});
|
||||
$("#tabcontrol-tab-1-3").click(function(){
|
||||
ccn_tabcontrol_SwitchTab(1, 3);
|
||||
});
|
||||
ccn_tabcontrol_SwitchTab(1, 1);
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
|
||||
//refresh once
|
||||
ccn_calendar_collection_Refresh();
|
||||
ccn_calendar_calendar_Refresh();
|
||||
ccn_calendar_calendar_Analyse();
|
||||
ccn_calendar_calendar_Render();
|
||||
|
||||
// bind event
|
||||
$('#ccn-calendar-collection-btnRefresh').click(ccn_calendar_collection_Refresh);
|
||||
|
||||
$('#ccn-calendar-calendar-btnJump')
|
||||
.prop('funcs', {callback: ccn_calendar_calendar_btnRefresh})
|
||||
.click(function() {
|
||||
ccn_datetimepicker_Modal(
|
||||
ccn_datetimepicker_tabType.month,
|
||||
1,
|
||||
false);
|
||||
});
|
||||
$('#ccn-calendar-calendar-btnToday').click(ccn_calendar_calendar_btnToday);
|
||||
$('#ccn-calendar-calendar-btnAdd').click(ccn_calendar_calendar_btnAdd);
|
||||
});
|
||||
|
||||
// ================== calendar
|
||||
|
||||
function ccn_calendar_calendar_LoadCalendarBody() {
|
||||
$('#ccn-calendar-calendarBody').append(ccn_template_calendarItem.render());
|
||||
}
|
||||
|
||||
// this function only refresh cache list
|
||||
function ccn_calendar_calendar_Refresh() {
|
||||
var gottenDateTime = ccn_datetimepicker_Get(1, false);
|
||||
var gottenYear = gottenDateTime.getFullYear();
|
||||
var gottenMonth = gottenDateTime.getMonth() + 1;
|
||||
$('#ccn-calendar-calendar-textMonth').text('{0} - {1}'.format(gottenYear, ccn_i18n_UniversalGetMonth(gottenMonth - 1)));
|
||||
// don't need to set anything, because its default value is enough to use.
|
||||
|
||||
var gottenWeek = ccn_datetime_DayOfWeek(gottenYear, gottenMonth, 1);
|
||||
var startTimestamp = Math.floor(gottenDateTime.getTime() / 60000) - gottenWeek * ccn_datetime_DAY1_SPAN;
|
||||
var endTimestamp = startTimestamp + ccn_datetime_DAY1_SPAN * 6 * 7 - 1;
|
||||
|
||||
ccn_calendar_calendar_listCache = new Array();
|
||||
var result = ccn_api_calendar_getFull(startTimestamp, endTimestamp);
|
||||
if (typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
ccn_calendar_calendar_listCache[result[index][0]] = result[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this function take responsibility to analyse event
|
||||
// call datetime function to resolve loop event
|
||||
// and split event if some event cross 2+ days
|
||||
function ccn_calendar_calendar_Analyse() {
|
||||
// first, we need construct ccn_calendar_calendar_displayCache
|
||||
ccn_calendar_calendar_displayCache = new Array();
|
||||
var gottenDateTime = ccn_datetimepicker_Get(1, false);
|
||||
var gottenYear = gottenDateTime.getFullYear();
|
||||
var gottenMonth = gottenDateTime.getMonth() + 1;
|
||||
var gottenWeek = ccn_datetime_DayOfWeek(gottenYear, gottenMonth, 1);
|
||||
var startTimestamp = Math.floor(gottenDateTime.getTime() / 60000) - gottenWeek * ccn_datetime_DAY1_SPAN;
|
||||
var endTimestamp = startTimestamp + ccn_datetime_DAY1_SPAN * 6 * 7 - 1;
|
||||
gottenDateTime.setTime(startTimestamp * 60000);
|
||||
for(var index = 0; index < 6 * 7; index++) {
|
||||
ccn_calendar_calendar_displayCache.push({
|
||||
month: gottenDateTime.getMonth() + 1,
|
||||
day: gottenDateTime.getDate(),
|
||||
dayOfWeek: gottenDateTime.getWeekday() + 1,
|
||||
subcalendar: "",
|
||||
isCurrentMonth: (gottenDateTime.getMonth() + 1) == gottenMonth,
|
||||
events: new Array()
|
||||
});
|
||||
gottenDateTime.setTime(gottenDateTime.getTime() + ccn_datetime_DAY1_SPAN * 60000);
|
||||
}
|
||||
|
||||
var mytimezone = -(new Date().getTimezoneOffset());
|
||||
// then analyse each event
|
||||
for(var index in ccn_calendar_calendar_listCache) {
|
||||
var item = ccn_calendar_calendar_listCache[index];
|
||||
var deserializedDescription = ccn_api_deserializeDescription(item[3]);
|
||||
|
||||
var minStartTimestamp = startTimestamp - (item[6] - item[5]);
|
||||
var result = ccn_datetime_ResolveLoopRules4Event(
|
||||
item[8],
|
||||
item[9] < minStartTimestamp ? minStartTimestamp : item[9],
|
||||
Math.min(item[10], endTimestamp),
|
||||
item[5],
|
||||
item[6],
|
||||
item[7],
|
||||
startTimestamp
|
||||
);
|
||||
if(typeof(result) != 'undefined') {
|
||||
for(var i in result) {
|
||||
var it = result[i];
|
||||
// try get event belong to which cell
|
||||
var eventDateTime = new Date(it[0] * 60000);
|
||||
var count = Math.floor((it[0] - startTimestamp) / ccn_datetime_DAY1_SPAN);
|
||||
var exitFlag = false;
|
||||
// then split event
|
||||
while(count < 6 * 7) {
|
||||
var eventItem = {
|
||||
uuid: item[0],
|
||||
belongTo: item[1],
|
||||
title: item[2],
|
||||
description: deserializedDescription.description,
|
||||
color: deserializedDescription.color,
|
||||
isVisible: true,
|
||||
isLocked: typeof(ccn_calendar_owned_displayCache[item[0]]) != 'undefined',
|
||||
loopText: ccn_datetime_ResolveLoopRules4Text(item[8], item[5], item[7]),
|
||||
timezoneWarning: mytimezone != item[7],
|
||||
start: eventDateTime.toLocaleTimeString(),
|
||||
end: undefined // filled in follwing code
|
||||
}
|
||||
eventDateTime.setHours(23, 59, 0, 0);
|
||||
if (it[1] <= Math.floor(eventDateTime.getTime() / 60000)) {
|
||||
exitFlag = true;
|
||||
eventDateTime.setTime(it[1] * 60000);
|
||||
}
|
||||
eventItem.end = eventDateTime.toLocaleTimeString();
|
||||
ccn_calendar_calendar_displayCache[count].events.push(eventItem);
|
||||
if (exitFlag) break;
|
||||
else eventDateTime.setMinutes(eventDateTime.getMinutes() + 1, 0, 0);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// just use produced ccn_calendar_calendar_displayCache
|
||||
// to re-generate ui
|
||||
function ccn_calendar_calendar_Render() {
|
||||
// todo: add / migrate subcalendar feature here
|
||||
|
||||
|
||||
// analyse visible data
|
||||
for(var i in ccn_calendar_calendar_displayCache) {
|
||||
for(var j in ccn_calendar_calendar_displayCache[i].events) {
|
||||
var gottenOwnedVisible = ccn_calendar_owned_displayCache[
|
||||
ccn_calendar_calendar_displayCache[i].events[j].belongTo
|
||||
];
|
||||
if (typeof(gottenOwnedVisible) == 'undefined') gottenOwnedVisible = false;
|
||||
var gottenSharedVisible = ccn_calendar_shared_displayCache[
|
||||
ccn_calendar_calendar_displayCache[i].events[j].belongTo
|
||||
];
|
||||
if (typeof(gottenSharedVisible) == 'undefined') gottenSharedVisible = false;
|
||||
|
||||
ccn_calendar_calendar_displayCache[i].events[j].isVisible = gottenOwnedVisible || gottenSharedVisible;
|
||||
}
|
||||
}
|
||||
|
||||
// just render them
|
||||
var listDOM = $('#ccn-calendar-scheduleList');
|
||||
listDOM.empty();
|
||||
listDOM.append(ccn_template_scheduleItem.render({renderdata: ccn_calendar_calendar_displayCache}));
|
||||
// link click event
|
||||
$('div.schedule-event-outter').click(ccn_calendar_calendar_ItemUpdate);
|
||||
|
||||
// all data has been alanysed, feedback to calendar body.
|
||||
var counter = 0;
|
||||
for(var i = 0; i < 6; i++) {
|
||||
for(var j = 0; j < 7; j++) {
|
||||
var item = ccn_calendar_calendar_displayCache[counter];
|
||||
var lenEvents = item.events.length;
|
||||
var eventsCounter = 0;
|
||||
|
||||
$('#ccn-calendarItem-' + i + '-' + j).attr('isCurrentMonth', item.isCurrentMonth ? 'true' : 'false');
|
||||
|
||||
$('#ccn-calendarItem-title-' + i + '-' + j).text(item.day);
|
||||
$('#ccn-calendarItem-desc-' + i + '-' + j).text(item.subcalendar);
|
||||
|
||||
|
||||
for(; eventsCounter < Math.min(lenEvents, 4); eventsCounter++) {
|
||||
$('#ccn-calendarItem-eventBox' + (eventsCounter + 1) + '-' + i + '-' + j)
|
||||
.css('background', item.events[eventsCounter].color)
|
||||
.attr('enableDisplay', 'true');
|
||||
}
|
||||
if (lenEvents > 4) {
|
||||
// more than 4 item, write number
|
||||
$('#ccn-calendarItem-task-' + i + '-' + j).text(
|
||||
$.i18n.prop('ccn-i18n-calendar-calendar-stripedEvents').format(lenEvents.toString())
|
||||
);
|
||||
} else {
|
||||
// otherwise, wipe out number
|
||||
$('#ccn-calendarItem-task-' + i + '-' + j).html(' ');
|
||||
// set others div are blank
|
||||
for(; eventsCounter < 4; eventsCounter++) {
|
||||
$('#ccn-calendarItem-eventBox' + (eventsCounter + 1) + '-' + i + '-' + j)
|
||||
.attr('enableDisplay', 'false');
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
ccn_i18n_ApplyLanguage2Content(listDOM);
|
||||
}
|
||||
|
||||
function ccn_calendar_calendar_btnRefresh() {
|
||||
ccn_calendar_calendar_Refresh();
|
||||
ccn_calendar_calendar_Analyse();
|
||||
ccn_calendar_calendar_Render();
|
||||
}
|
||||
|
||||
function ccn_calendar_calendar_btnToday() {
|
||||
var nowtime = new Date();
|
||||
ccn_datetimepicker_Set(1, nowtime, false, ccn_datetimepicker_tabType.month);
|
||||
ccn_calendar_calendar_Refresh();
|
||||
ccn_calendar_calendar_Analyse();
|
||||
ccn_calendar_calendar_Render();
|
||||
}
|
||||
|
||||
function ccn_calendar_calendar_btnAdd() {
|
||||
window.location.href = '/web/eventAdd';
|
||||
}
|
||||
|
||||
function ccn_calendar_calendar_ItemUpdate() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
window.location.href = '/web/eventUpdate/' + uuid;
|
||||
}
|
||||
|
||||
// ============================= collection
|
||||
|
||||
function ccn_calendar_collection_Refresh() {
|
||||
ccn_calendar_owned_displayCache = new Array();
|
||||
ccn_calendar_shared_displayCache = new Array();
|
||||
|
||||
// render shared
|
||||
var result = ccn_api_collection_getShared();
|
||||
var listDOM = $('#ccn-calendar-sharedList');
|
||||
listDOM.empty();
|
||||
var renderdata = {
|
||||
uuid: undefined,
|
||||
name: undefined,
|
||||
username: undefined
|
||||
}
|
||||
if (typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
var item = result[index];
|
||||
renderdata.uuid = item[0];
|
||||
renderdata.name = item[1];
|
||||
renderdata.username = item[2];
|
||||
|
||||
listDOM.append(ccn_template_displaySharedItem.render(renderdata));
|
||||
|
||||
// change display
|
||||
var uuid = renderdata.uuid;
|
||||
ccn_calendar_shared_ChangeDisplayMode(uuid, true);
|
||||
|
||||
// push into display list
|
||||
ccn_calendar_shared_displayCache[uuid] = true;
|
||||
|
||||
// bind event
|
||||
$('#ccn-displaySharedItem-btnHide-' + uuid).click(ccn_calendar_shared_ItemSwitchDisplay);
|
||||
$('#ccn-displaySharedItem-btnShow-' + uuid).click(ccn_calendar_shared_ItemSwitchDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
ccn_i18n_ApplyLanguage2Content(listDOM);
|
||||
|
||||
// render owned
|
||||
result = ccn_api_collection_getFullOwn();
|
||||
listDOM = $('#ccn-calendar-ownedList');
|
||||
listDOM.empty();
|
||||
renderdata = {
|
||||
uuid: undefined,
|
||||
name: undefined
|
||||
}
|
||||
if (typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
var item = result[index];
|
||||
renderdata.uuid = item[0];
|
||||
renderdata.name = item[1];
|
||||
|
||||
// render
|
||||
listDOM.append(ccn_template_displayOwnedItem.render(renderdata));
|
||||
|
||||
// set mode
|
||||
var uuid = renderdata.uuid;
|
||||
ccn_calendar_owned_ChangeDisplayMode(uuid, true);
|
||||
|
||||
// push into display list
|
||||
ccn_calendar_owned_displayCache[uuid] = true;
|
||||
|
||||
// bind event
|
||||
$('#ccn-displayOwnedItem-btnHide-' + uuid).click(ccn_calendar_owned_ItemSwitchDisplay);
|
||||
$('#ccn-displayOwnedItem-btnShow-' + uuid).click(ccn_calendar_owned_ItemSwitchDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ccn_calendar_owned_ItemSwitchDisplay() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
ccn_calendar_owned_displayCache[uuid] = !(ccn_calendar_owned_displayCache[uuid]);
|
||||
ccn_calendar_owned_ChangeDisplayMode(uuid, ccn_calendar_owned_displayCache[uuid]);
|
||||
}
|
||||
|
||||
function ccn_calendar_shared_ItemSwitchDisplay() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
ccn_calendar_shared_displayCache[uuid] = !(ccn_calendar_shared_displayCache[uuid]);
|
||||
ccn_calendar_shared_ChangeDisplayMode(uuid, ccn_calendar_shared_displayCache[uuid]);
|
||||
}
|
||||
|
||||
function ccn_calendar_shared_ChangeDisplayMode(uuid, isShow) {
|
||||
if (isShow) {
|
||||
$('#ccn-displaySharedItem-btnHide-' + uuid).show();
|
||||
$('#ccn-displaySharedItem-btnShow-' + uuid).hide();
|
||||
} else {
|
||||
$('#ccn-displaySharedItem-btnHide-' + uuid).hide();
|
||||
$('#ccn-displaySharedItem-btnShow-' + uuid).show();
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_calendar_owned_ChangeDisplayMode(uuid, isShow) {
|
||||
if (isShow) {
|
||||
$('#ccn-displayOwnedItem-btnHide-' + uuid).show();
|
||||
$('#ccn-displayOwnedItem-btnShow-' + uuid).hide();
|
||||
} else {
|
||||
$('#ccn-displayOwnedItem-btnHide-' + uuid).hide();
|
||||
$('#ccn-displayOwnedItem-btnShow-' + uuid).show();
|
||||
}
|
||||
}
|
||||
288
frontend-legacy/static/js/page/collection.js
Normal file
288
frontend-legacy/static/js/page/collection.js
Normal file
@@ -0,0 +1,288 @@
|
||||
// 3 used cache list
|
||||
var ccn_collection_owned_listCache = [];
|
||||
var ccn_collection_sharing_listCache = [];
|
||||
|
||||
// current editing sharing collection
|
||||
var ccn_collection_sharing_editingOwned = undefined; // the uuid of owned collection
|
||||
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.collection;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
ccn_messagebox_Insert();
|
||||
ccn_messagebox_BindEvent();
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
|
||||
//refresh once
|
||||
ccn_collection_owned_Refresh();
|
||||
|
||||
// bind event
|
||||
//$('#ccn-calendar-shared-btnRefresh').click(ccn_calendar_shared_Refresh);
|
||||
$('#ccn-collection-owned-btnAdd').click(ccn_collection_owned_Add);
|
||||
$('#ccn-collection-owned-btnRefresh').click(ccn_collection_owned_Refresh);
|
||||
$('#ccn-collection-sharing-btnAdd').click(ccn_collection_sharing_Add);
|
||||
$('#ccn-collection-sharing-btnRefresh').click(ccn_collection_sharing_Refresh);
|
||||
|
||||
});
|
||||
|
||||
|
||||
function ccn_collection_owned_Refresh() {
|
||||
ccn_collection_owned_listCache = new Array();
|
||||
ccn_collection_sharing_displayCache = new Array();
|
||||
|
||||
var result = ccn_api_collection_getFullOwn();
|
||||
if(typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
ccn_collection_owned_listCache[result[index][0]] = result[index];
|
||||
}
|
||||
}
|
||||
|
||||
// render
|
||||
var listDOM = $('#ccn-collection-ownedList');
|
||||
listDOM.empty();
|
||||
for(var index in ccn_collection_owned_listCache) {
|
||||
ccn_collection_owned_RenderItem(
|
||||
ccn_collection_owned_listCache[index],
|
||||
listDOM
|
||||
);
|
||||
}
|
||||
|
||||
// also, order sharing list clean
|
||||
ccn_collection_sharing_editingOwned = undefined;
|
||||
ccn_collection_sharing_Refresh();
|
||||
}
|
||||
|
||||
function ccn_collection_owned_RenderItem(item, listDOM) {
|
||||
var renderdata = {
|
||||
uuid: item[0],
|
||||
name: item[1]
|
||||
}
|
||||
|
||||
// render
|
||||
listDOM.append(ccn_template_ownedItem.render(renderdata));
|
||||
|
||||
// set mode
|
||||
var uuid = renderdata.uuid;
|
||||
ccn_collection_owned_ChangeDisplayMode(uuid, false);
|
||||
|
||||
// bind event
|
||||
$('#ccn-ownedItem-btnEdit-' + uuid).click(ccn_collection_owned_ItemEdit);
|
||||
$('#ccn-ownedItem-btnDelete-' + uuid).click(ccn_collection_owned_ItemDelete);
|
||||
$('#ccn-ownedItem-btnShare-' + uuid).click(ccn_collection_owned_ItemShare);
|
||||
$('#ccn-ownedItem-btnUpdate-' + uuid).click(ccn_collection_owned_ItemUpdate);
|
||||
$('#ccn-ownedItem-btnCancelUpdate-' + uuid).click(ccn_collection_owned_ItemCancelUpdate);
|
||||
|
||||
}
|
||||
|
||||
function ccn_collection_owned_ChangeDisplayMode(uuid, isEdit) {
|
||||
if (isEdit) {
|
||||
$('#ccn-ownedItem-btnEdit-' + uuid).hide();
|
||||
$('#ccn-ownedItem-btnShare-' + uuid).hide();
|
||||
$('#ccn-ownedItem-btnDelete-' + uuid).hide();
|
||||
|
||||
$('#ccn-ownedItem-btnUpdate-' + uuid).show();
|
||||
$('#ccn-ownedItem-btnCancelUpdate-' + uuid).show();
|
||||
|
||||
$('#ccn-ownedItem-textName-' + uuid).hide();
|
||||
$('#ccn-ownedItem-boxName-' + uuid).show();
|
||||
} else {
|
||||
$('#ccn-ownedItem-btnEdit-' + uuid).show();
|
||||
$('#ccn-ownedItem-btnShare-' + uuid).show();
|
||||
$('#ccn-ownedItem-btnDelete-' + uuid).show();
|
||||
|
||||
$('#ccn-ownedItem-btnUpdate-' + uuid).hide();
|
||||
$('#ccn-ownedItem-btnCancelUpdate-' + uuid).hide();
|
||||
|
||||
$('#ccn-ownedItem-textName-' + uuid).show();
|
||||
$('#ccn-ownedItem-boxName-' + uuid).hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ccn_collection_sharing_Refresh() {
|
||||
ccn_collection_sharing_listCache = new Array();
|
||||
|
||||
if (typeof(ccn_collection_sharing_editingOwned) != 'undefined') {
|
||||
var result = ccn_api_collection_getSharing(ccn_collection_sharing_editingOwned);
|
||||
if (typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
ccn_collection_sharing_listCache[index] = result[index];
|
||||
// also, sharingTarget don't have uuid, use index instead
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update editing text
|
||||
$('#ccn-collection-sharing-sharingEditing').text(
|
||||
typeof(ccn_collection_sharing_editingOwned) == 'undefined' ?
|
||||
'' :
|
||||
ccn_collection_owned_listCache[ccn_collection_sharing_editingOwned][1]
|
||||
);
|
||||
|
||||
// if editing is undefined, hide container
|
||||
if (typeof(ccn_collection_sharing_editingOwned) == 'undefined')
|
||||
$('#ccn-collection-sharing-container').hide();
|
||||
else
|
||||
$('#ccn-collection-sharing-container').show();
|
||||
|
||||
|
||||
var listDOM = $('#ccn-collection-sharingList');
|
||||
listDOM.empty();
|
||||
for(var index in ccn_collection_sharing_listCache) {
|
||||
ccn_collection_sharing_RenderItem(
|
||||
ccn_collection_sharing_listCache[index],
|
||||
index,
|
||||
listDOM
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_collection_sharing_RenderItem(item, index, listDOM) {
|
||||
var renderdata = {
|
||||
uuid: index,
|
||||
username: item
|
||||
}
|
||||
|
||||
// render
|
||||
listDOM.append(ccn_template_sharingItem.render(renderdata));
|
||||
|
||||
// bind event
|
||||
var uuid = index;
|
||||
$("#ccn-sharingItem-btnDelete-" + uuid).click(ccn_collection_sharing_ItemDelete);
|
||||
}
|
||||
|
||||
// ========================= input operation
|
||||
|
||||
function ccn_collection_owned_Add() {
|
||||
var newname = $('#ccn-collection-owned-inputAdd').val();
|
||||
if (newname == "") return;
|
||||
|
||||
var result = ccn_api_collection_addOwn(newname);
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-add"));
|
||||
else {
|
||||
// second get. get detail
|
||||
result = ccn_api_collection_getDetailOwn(result);
|
||||
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-get"));
|
||||
else {
|
||||
// render
|
||||
ccn_collection_owned_listCache[result[0]] = result;
|
||||
var listDOM = $('#ccn-collection-ownedList');
|
||||
ccn_collection_owned_RenderItem(result, listDOM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_collection_owned_ItemEdit() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
// preset inputbox
|
||||
$('#ccn-ownedItem-inputName-' + uuid).val(
|
||||
ccn_collection_owned_listCache[uuid][1]
|
||||
);
|
||||
|
||||
// switch to edit mode
|
||||
ccn_collection_owned_ChangeDisplayMode(uuid, true);
|
||||
}
|
||||
|
||||
function ccn_collection_owned_ItemDelete() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
var result = ccn_api_collection_deleteOwn(
|
||||
uuid,
|
||||
ccn_collection_owned_listCache[uuid][2]
|
||||
);
|
||||
if (!result) ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-delete"));
|
||||
else {
|
||||
$('#ccn-ownedItem-' + uuid).remove();
|
||||
|
||||
// also, we should notice sharing target, and try clean it
|
||||
if (ccn_collection_sharing_editingOwned == uuid) {
|
||||
ccn_collection_sharing_editingOwned = undefined;
|
||||
ccn_collection_sharing_Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_collection_owned_ItemUpdate() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
var newname = $('#ccn-ownedItem-inputName-' + uuid).val();
|
||||
|
||||
var result = ccn_api_collection_updateOwn(uuid, newname, ccn_collection_owned_listCache[uuid][2]);
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-update"));
|
||||
else {
|
||||
// update last change
|
||||
ccn_collection_owned_listCache[uuid][2] = result;
|
||||
ccn_collection_owned_listCache[uuid][1] = newname;
|
||||
// update elements
|
||||
$('#ccn-ownedItem-textName-' + uuid).text(newname);
|
||||
// if editing, update sharing target
|
||||
if (ccn_collection_sharing_editingOwned == uuid)
|
||||
ccn_collection_sharing_Refresh();
|
||||
// back to normal mode
|
||||
ccn_collection_owned_ChangeDisplayMode(uuid, false);
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_collection_owned_ItemCancelUpdate() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
ccn_collection_owned_ChangeDisplayMode(uuid, false);
|
||||
}
|
||||
|
||||
function ccn_collection_owned_ItemShare() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
ccn_collection_sharing_editingOwned = uuid;
|
||||
ccn_collection_sharing_Refresh();
|
||||
}
|
||||
|
||||
|
||||
function ccn_collection_sharing_Add() {
|
||||
var newusername = $('#ccn-collection-sharing-inputAdd').val();
|
||||
if (newusername == "" || typeof(ccn_collection_sharing_editingOwned) == 'undefined') return;
|
||||
|
||||
var result = ccn_api_collection_addSharing(
|
||||
ccn_collection_sharing_editingOwned,
|
||||
newusername,
|
||||
ccn_collection_owned_listCache[ccn_collection_sharing_editingOwned][2]
|
||||
);
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-add"));
|
||||
else {
|
||||
// add new item
|
||||
var index = ccn_collection_sharing_listCache.push(newusername) - 1;
|
||||
var listDOM = $('#ccn-collection-sharingList');
|
||||
ccn_collection_sharing_RenderItem(newusername, index, listDOM);
|
||||
// update last change
|
||||
ccn_collection_owned_listCache[ccn_collection_sharing_editingOwned][2] = result;
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_collection_sharing_ItemDelete() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
var username = ccn_collection_sharing_listCache[uuid];
|
||||
|
||||
var result = ccn_api_collection_deleteSharing(
|
||||
ccn_collection_sharing_editingOwned,
|
||||
username,
|
||||
ccn_collection_owned_listCache[ccn_collection_sharing_editingOwned][2]
|
||||
);
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-delete"));
|
||||
else {
|
||||
// remove item in ui
|
||||
$('#ccn-sharingItem-' + uuid).remove();
|
||||
// update last change
|
||||
ccn_collection_owned_listCache[ccn_collection_sharing_editingOwned][2] = result;
|
||||
}
|
||||
}
|
||||
|
||||
447
frontend-legacy/static/js/page/event.js
Normal file
447
frontend-legacy/static/js/page/event.js
Normal file
@@ -0,0 +1,447 @@
|
||||
// if it is undefined, current mode is add
|
||||
// or it is the detail data gotten from api
|
||||
var ccn_event_editingEvent = undefined;
|
||||
var ccn_event_collectionCache = [];
|
||||
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.event;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
ccn_messagebox_Insert();
|
||||
ccn_messagebox_BindEvent();
|
||||
|
||||
// init datetimepicker
|
||||
ccn_datetimepicker_Insert();
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
|
||||
// bind event
|
||||
$('input[type=radio][name=loop-method]').click(ccn_event_RefreshRadioDiaplay);
|
||||
$('input[type=radio][name=loop-end]').click(ccn_event_RefreshRadioDiaplay);
|
||||
|
||||
$('#ccn-event-btnSubmit').click(ccn_event_btnSubmit);
|
||||
$('#ccn-event-btnCancel').click(ccn_event_btnCancel);
|
||||
$('#ccn-event-btnSpot').click(ccn_event_btnSpot);
|
||||
$('#ccn-event-btnFullDay').click(ccn_event_btnFullDay);
|
||||
$('#ccn-event-btnStartDateTime')
|
||||
.prop('funcs', {callback: function() {
|
||||
ccn_event_UpdateDateTimePickerButton(1);
|
||||
ccn_event_RefreshLoopMonthType();
|
||||
}})
|
||||
.click(ccn_event_btnDateTimePicker);
|
||||
$('#ccn-event-btnEndDateTime')
|
||||
.prop('funcs', {callback: function() {ccn_event_UpdateDateTimePickerButton(2);}})
|
||||
.click(ccn_event_btnDateTimePicker);
|
||||
$('#ccn-event-btnLoopStopDateTime')
|
||||
.prop('funcs', {callback: function() {ccn_event_UpdateDateTimePickerButton(3);}})
|
||||
.click(ccn_event_btnDateTimePicker);
|
||||
|
||||
// init form
|
||||
ccn_event_Init();
|
||||
|
||||
// refresh once
|
||||
ccn_event_RefreshRadioDiaplay();
|
||||
ccn_event_RefreshLoopMonthType();
|
||||
});
|
||||
|
||||
|
||||
function ccn_event_Init() {
|
||||
// we need init some elements first
|
||||
|
||||
// we need all radio and checkbox's checked is false, not undefined.
|
||||
$('input[type=radio]').prop("checked", false);
|
||||
$('input[type=checkbox]').prop("checked", false);
|
||||
|
||||
// init span picker
|
||||
$('.spanpicker').attr('max', 100)
|
||||
.attr('min', 1)
|
||||
.attr('step', 1)
|
||||
.val(1);
|
||||
|
||||
// in there, we need get uuid from meta
|
||||
var uuid = $('meta[name=uuid]').attr('content');
|
||||
if (uuid != "")
|
||||
ccn_event_editingEvent = ccn_api_calendar_getDetail(uuid);
|
||||
// if ccn_event_editingEvent is undefined, init following content with add mode
|
||||
// otherwise, init as update mode
|
||||
var isAdd = typeof(ccn_event_editingEvent) == 'undefined';
|
||||
var deserializeDescription = isAdd ? undefined : ccn_api_deserializeDescription(ccn_event_editingEvent[3]);
|
||||
|
||||
// init title and description
|
||||
$('#ccn-event-inputTitle').val(
|
||||
isAdd ? '' : ccn_event_editingEvent[2]
|
||||
);
|
||||
$('#ccn-event-inputDescription').val(
|
||||
isAdd ? '' : deserializeDescription.description
|
||||
);
|
||||
$('#ccn-event-inputColor').val(
|
||||
isAdd ? DefaultColor : deserializeDescription.color
|
||||
);
|
||||
|
||||
// init collection picker, first we need query data
|
||||
// and render it
|
||||
var collectionDOM = $('#ccn-event-inputCollection');
|
||||
collectionDOM.empty();
|
||||
ccn_event_collectionCache = new Array();
|
||||
var result = ccn_api_collection_getFullOwn();
|
||||
if (typeof(result) != 'undefined') {
|
||||
var renderdata = {
|
||||
val: undefined,
|
||||
name: undefined
|
||||
}
|
||||
|
||||
for (var index in result) {
|
||||
var item = result[index];
|
||||
ccn_event_collectionCache.push(item[0])
|
||||
renderdata.val = item[0];
|
||||
renderdata.name = item[1];
|
||||
collectionDOM.append(
|
||||
ccn_template_optionItem.render(renderdata)
|
||||
);
|
||||
}
|
||||
}
|
||||
// in add mode, set as -1, otherwise try to match original data
|
||||
// indexOf will return -1 if no matched item
|
||||
collectionDOM.val(isAdd ? '' : ccn_event_editingEvent[1]);
|
||||
|
||||
// init start and end datetime
|
||||
if (isAdd) {
|
||||
// in add mode, init 2 datetime picker as close hours based time.
|
||||
var currentDateTime = new Date();
|
||||
currentDateTime.setMilliseconds(0);
|
||||
currentDateTime.setSeconds(0);
|
||||
currentDateTime.setMinutes(0);
|
||||
ccn_datetimepicker_Set(1, currentDateTime, false);
|
||||
|
||||
// time span is 2 hours
|
||||
currentDateTime.setHours(currentDateTime.getHours() + 2);
|
||||
ccn_datetimepicker_Set(2, currentDateTime, false);
|
||||
} else {
|
||||
// in update mode, match it with original data
|
||||
var originalDateTime = new Date((ccn_event_editingEvent[5] + ccn_event_editingEvent[7]) * 60000);
|
||||
ccn_datetimepicker_Set(1, originalDateTime, true);
|
||||
|
||||
originalDateTime = new Date((ccn_event_editingEvent[6] + ccn_event_editingEvent[7]) * 60000);
|
||||
ccn_datetimepicker_Set(2, originalDateTime, true);
|
||||
}
|
||||
|
||||
// setup timezone here
|
||||
// to prevent some error
|
||||
// because following isAdd will change its meaning
|
||||
$('#ccn-event-timezone-radioKeep').prop('checked', true); // give a default value
|
||||
var nowtime = new Date();
|
||||
SmarterShowHide(
|
||||
(!isAdd) && (-nowtime.getTimezoneOffset()) != ccn_event_editingEvent[7],
|
||||
$('#ccn-event-boxTimezone')
|
||||
);
|
||||
|
||||
// ========================
|
||||
// now we need resolve loop rules and set related data
|
||||
if (!isAdd) {
|
||||
data = ccn_datetime_ResolveLoopRules4UI(ccn_event_editingEvent[8]);
|
||||
if (typeof(data) == 'undefined') isAdd = true; // init as add
|
||||
}
|
||||
|
||||
// give some value with a default value
|
||||
$('#ccn-event-loopMonth-radioA').prop('checked', true);
|
||||
$('#ccn-event-loopWeek-check' + (nowtime.getWeekday() + 1)).prop('checked', true);
|
||||
$('#ccn-event-strictMode-radioStrict').prop('checked', true);
|
||||
|
||||
// real process
|
||||
if (isAdd) {
|
||||
$('#ccn-event-radioLoopNever').prop('checked', true);
|
||||
} else {
|
||||
switch(data[0][0]) {
|
||||
case 0:
|
||||
$('#ccn-event-radioLoopYear').prop('checked', true);
|
||||
$('#ccn-event-loopYear-inputSpan').val(data[0][2]);
|
||||
if (data[0][1]) $('#ccn-event-strictMode-radioStrict').prop('checked', true);
|
||||
else $('#ccn-event-strictMode-radioRough').prop('checked', true);
|
||||
break;
|
||||
case 1:
|
||||
$('#ccn-event-radioLoopMonth').prop('checked', true);
|
||||
$('#ccn-event-loopMonth-inputSpan').val(data[0][3]);
|
||||
$('#ccn-event-loopMonth-radio' + data[0][2]).prop('checked', true);
|
||||
if (data[0][1]) $('#ccn-event-strictMode-radioStrict').prop('checked', true);
|
||||
else $('#ccn-event-strictMode-radioRough').prop('checked', true);
|
||||
break;
|
||||
case 2:
|
||||
$('#ccn-event-radioLoopWeek').prop('checked', true);
|
||||
$('#ccn-event-loopWeek-inputSpan').val(data[0][8]);
|
||||
for(var i = 1; i <= 7; i++) {
|
||||
$('#ccn-event-loopWeek-check' + i).prop('checked', data[0][i]);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
$('#ccn-event-radioLoopDay').prop('checked', true);
|
||||
$('#ccn-event-loopDay-inputSpan').val(data[0][1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// give some item a default value
|
||||
ccn_datetimepicker_Set(3, nowtime, false);
|
||||
|
||||
if (isAdd) {
|
||||
$('#ccn-event-loopStop-radioForever').prop('checked', true);
|
||||
} else {
|
||||
switch(data[1][0]) {
|
||||
case 0:
|
||||
$('#ccn-event-loopStop-radioForever').prop('checked', true);
|
||||
break;
|
||||
case 1:
|
||||
$('#ccn-event-loopStop-radioDateTime').prop('checked', true);
|
||||
var stopDatetime = new Date((data[1][1] + ccn_event_editingEvent[7]) * 60000);
|
||||
ccn_datetimepicker_Set(3, stopDatetime, true);
|
||||
break;
|
||||
case 2:
|
||||
$('#ccn-event-loopStop-radioTimes').prop('checked', true);
|
||||
$('#ccn-event-loopStop-inputTimes').val(data[1][1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// refresh some ui element according to form options
|
||||
function ccn_event_RefreshRadioDiaplay() {
|
||||
// loop method
|
||||
// note: no loop control loop stop's display
|
||||
// note: year and month loop also control strict mode display
|
||||
SmarterShowHide(!$('#ccn-event-radioLoopNever').prop('checked'), $('#ccn-event-boxLoopStop'));
|
||||
|
||||
SmarterShowHide($('#ccn-event-radioLoopDay').prop('checked'), $('#ccn-event-boxLoopDay'));
|
||||
SmarterShowHide($('#ccn-event-radioLoopWeek').prop('checked'), $('#ccn-event-boxLoopWeek'));
|
||||
SmarterShowHide($('#ccn-event-radioLoopMonth').prop('checked'), $('#ccn-event-boxLoopMonth'));
|
||||
SmarterShowHide($('#ccn-event-radioLoopYear').prop('checked'), $('#ccn-event-boxLoopYear'));
|
||||
|
||||
SmarterShowHide(
|
||||
$('#ccn-event-radioLoopMonth').prop('checked') || $('#ccn-event-radioLoopYear').prop('checked'),
|
||||
$('#ccn-event-boxStrictMode')
|
||||
);
|
||||
|
||||
// loop stop
|
||||
SmarterShowHide($('#ccn-event-loopStop-radioForever').prop('checked'), undefined);
|
||||
SmarterShowHide($('#ccn-event-loopStop-radioDateTime').prop('checked'), $('#ccn-event-boxLoopStopDateTime'));
|
||||
SmarterShowHide($('#ccn-event-loopStop-radioTimes').prop('checked'), $('#ccn-event-boxLoopStopTimes'));
|
||||
|
||||
}
|
||||
|
||||
function ccn_event_RefreshLoopMonthType() {
|
||||
var picker = ccn_datetimepicker_Get(1, false);
|
||||
var data = ccn_datetime_GetDayInMonth(picker.getFullYear(), picker.getMonth() + 1, picker.getDate());
|
||||
|
||||
$('#ccn-event-loopMonth-textA').text($.i18n.prop('ccn-i18n-event-loopWeek-optionA').format(data[0]));
|
||||
$('#ccn-event-loopMonth-textB').text($.i18n.prop('ccn-i18n-event-loopWeek-optionB').format(data[1]));
|
||||
$('#ccn-event-loopMonth-textC').text($.i18n.prop('ccn-i18n-event-loopWeek-optionC').format(data[2], data[3] + 1));
|
||||
$('#ccn-event-loopMonth-textD').text($.i18n.prop('ccn-i18n-event-loopWeek-optionD').format(data[4], data[5] + 1));
|
||||
}
|
||||
|
||||
function ccn_event_UpdateDateTimePickerButton(index) {
|
||||
switch(index) {
|
||||
case 1:
|
||||
$('#ccn-event-btnStartDateTime-text').text(
|
||||
ccn_datetimepicker_Get(1, false).toLocaleString()
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
$('#ccn-event-btnEndDateTime-text').text(
|
||||
ccn_datetimepicker_Get(2, false).toLocaleString()
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
$('#ccn-event-btnLoopStopDateTime-text').text(
|
||||
ccn_datetimepicker_Get(3, false).toLocaleDateString()
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// return undefined to indicate an error
|
||||
// or
|
||||
// [belongTo, title, description, eventDateTimeStart, eventDateTimeEnd, timezoneOffset, loopRules]
|
||||
function ccn_event_GetForm() {
|
||||
// basic
|
||||
var title = $('#ccn-event-inputTitle').val();
|
||||
if (title == '') return undefined;
|
||||
var description = $('#ccn-event-inputDescription').val();
|
||||
if (description == '') return undefined;
|
||||
var color = $('#ccn-event-inputColor').val();
|
||||
if (color == '') return undefined;
|
||||
var belongTo = $('#ccn-event-inputCollection').val();
|
||||
if (belongTo == null) return undefined; // if no selected item, val return null, not undefined
|
||||
|
||||
var isAdd = typeof(ccn_event_editingEvent) == 'undefined';
|
||||
var keepTimezone = $('#ccn-event-timezone-radioKeep').prop('checked');
|
||||
var isStrict = $('#ccn-event-strictMode-radioStrict').prop('checked');
|
||||
|
||||
// time
|
||||
var eventDateTimeStart = undefined;
|
||||
var eventDateTimeEnd = undefined;
|
||||
var timezoneOffset = undefined;
|
||||
if ((!isAdd) && (!keepTimezone)) {
|
||||
// get datetime as utc, then minus original timezone to get unix timestamp
|
||||
timezoneOffset = ccn_event_editingEvent[7]; // keep timezone
|
||||
eventDateTimeStart = Math.floor(ccn_datetimepicker_Get(1, true).getTime() / 60000) - timezoneOffset;
|
||||
eventDateTimeEnd = Math.floor(ccn_datetimepicker_Get(2, true).getTime() / 60000) - timezoneOffset;
|
||||
} else {
|
||||
// use my timezone, resolve presented data as my local time
|
||||
var cache = ccn_datetimepicker_Get(1, false);
|
||||
timezoneOffset = -cache.getTimezoneOffset();
|
||||
eventDateTimeStart = Math.floor(cache.getTime() / 60000);
|
||||
eventDateTimeEnd = Math.floor(ccn_datetimepicker_Get(2, false).getTime() / 60000);
|
||||
}
|
||||
|
||||
// loopRules
|
||||
var loopRules = undefined;
|
||||
if ($('#ccn-event-radioLoopNever').prop('checked')) {
|
||||
loopRules = "";
|
||||
} else if ($('#ccn-event-radioLoopDay').prop('checked')) {
|
||||
loopRules = "D{0}".format($('#ccn-event-loopDay-inputSpan').val());
|
||||
} else if ($('#ccn-event-radioLoopWeek').prop('checked')) {
|
||||
var cache = ""
|
||||
for(var i = 1; i < 8; i++)
|
||||
cache += $('#ccn-event-loopWeek-check' + i).prop('checked') ? 'T' : 'F';
|
||||
loopRules = 'W{0}{1}'.format(
|
||||
cache,
|
||||
$('#ccn-event-loopWeek-inputSpan').val()
|
||||
);
|
||||
} else if ($('#ccn-event-radioLoopMonth').prop('checked')) {
|
||||
var cache = undefined;
|
||||
if ($('#ccn-event-loopMonth-radioA').prop('checked')) cache='A';
|
||||
else if ($('#ccn-event-loopMonth-radioB').prop('checked')) cache='B';
|
||||
else if ($('#ccn-event-loopMonth-radioC').prop('checked')) cache='C';
|
||||
else if ($('#ccn-event-loopMonth-radioD').prop('checked')) cache='D';
|
||||
else return undefined;
|
||||
|
||||
loopRules = "M{0}{1}{2}".format(
|
||||
isStrict ? "S" : "R",
|
||||
cache,
|
||||
$('#ccn-event-loopMonth-inputSpan').val()
|
||||
);
|
||||
} else if ($('#ccn-event-radioLoopYear').prop('checked')) {
|
||||
loopRules = "Y{0}{1}".format(
|
||||
isStrict ? "S" : "R",
|
||||
$('#ccn-event-loopYear-inputSpan').val()
|
||||
);
|
||||
}
|
||||
|
||||
// no need to process stop if this is not a loop event
|
||||
if (loopRules != "") {
|
||||
loopRules += '-';
|
||||
if ($('#ccn-event-loopStop-radioForever').prop('checked')) {
|
||||
loopRules += 'F';
|
||||
} else if ($('#ccn-event-loopStop-radioDateTime').prop('checked')) {
|
||||
var timestamp = undefined;
|
||||
if ((!isAdd) && (!keepTimezone)) {
|
||||
// keep timezone
|
||||
var cache = ccn_datetimepicker_Get(3, true);
|
||||
cache.setUTCHours(23);
|
||||
cache.setUTCMinutes(59);
|
||||
timestamp = Math.floor(cache.getTime() / 60000) - timezoneOffset;
|
||||
} else {
|
||||
// use my timezone
|
||||
timestamp = Math.floor(ccn_datetimepicker_Get(3, false).getTime() / 60000);
|
||||
}
|
||||
|
||||
loopRules += 'D{0}'.format(timestamp);
|
||||
} else if ($('#ccn-event-loopStop-radioTimes').prop('checked')) {
|
||||
loopRules += 'T{0}'.format($('#ccn-event-loopStop-inputTimes').val());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
belongTo,
|
||||
title,
|
||||
ccn_api_serializeDescription(
|
||||
description,
|
||||
color
|
||||
),
|
||||
eventDateTimeStart,
|
||||
eventDateTimeEnd,
|
||||
timezoneOffset,
|
||||
loopRules
|
||||
];
|
||||
}
|
||||
|
||||
function ccn_event_btnSpot() {
|
||||
var datetime = ccn_datetimepicker_Get(1, false);
|
||||
datetime.setMinutes(datetime.getMinutes() + 1);
|
||||
ccn_datetimepicker_Set(2, datetime, false);
|
||||
}
|
||||
|
||||
function ccn_event_btnFullDay() {
|
||||
var datetime = ccn_datetimepicker_Get(1, false);
|
||||
datetime.setMinutes(0);
|
||||
datetime.setHours(0);
|
||||
ccn_datetimepicker_Set(1, datetime, false);
|
||||
datetime.setMinutes(59);
|
||||
datetime.setHours(23);
|
||||
ccn_datetimepicker_Set(2, datetime, false);
|
||||
}
|
||||
|
||||
function ccn_event_btnDateTimePicker() {
|
||||
switch(parseInt($(this).attr('datetimepicker'))) {
|
||||
case 1:
|
||||
ccn_datetimepicker_Modal(ccn_datetimepicker_tabType.minute, 1, false);
|
||||
break;
|
||||
case 2:
|
||||
ccn_datetimepicker_Modal(ccn_datetimepicker_tabType.minute, 2, false);
|
||||
break;
|
||||
case 3:
|
||||
ccn_datetimepicker_Modal(ccn_datetimepicker_tabType.day, 3, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_event_btnCancel() {
|
||||
window.location.href = '/web/calendar';
|
||||
}
|
||||
|
||||
function ccn_event_btnSubmit() {
|
||||
var submitData = ccn_event_GetForm();
|
||||
if (typeof(submitData) == 'undefined') {
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-form"));
|
||||
return;
|
||||
}
|
||||
|
||||
var isAdd = typeof(ccn_event_editingEvent) == 'undefined';
|
||||
if (isAdd) {
|
||||
var result = ccn_api_calendar_add(
|
||||
submitData[0],
|
||||
submitData[1],
|
||||
submitData[2],
|
||||
submitData[3],
|
||||
submitData[4],
|
||||
submitData[6],
|
||||
submitData[5]
|
||||
);
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-add"));
|
||||
else window.location.href = '/web/calendar';
|
||||
} else {
|
||||
var result = ccn_api_calendar_update(
|
||||
ccn_event_editingEvent[0],
|
||||
ccn_event_editingEvent[1] == submitData[0] ? undefined : submitData[0],
|
||||
ccn_event_editingEvent[2] == submitData[1] ? undefined : submitData[1],
|
||||
ccn_event_editingEvent[3] == submitData[2] ? undefined : submitData[2],
|
||||
ccn_event_editingEvent[5] == submitData[3] ? undefined : submitData[3],
|
||||
ccn_event_editingEvent[6] == submitData[4] ? undefined : submitData[4],
|
||||
ccn_event_editingEvent[8] == submitData[6] ? undefined : submitData[6],
|
||||
ccn_event_editingEvent[7] == submitData[5] ? undefined : submitData[5],
|
||||
ccn_event_editingEvent[4]
|
||||
);
|
||||
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-update"));
|
||||
else window.location.href = '/web/calendar';
|
||||
}
|
||||
}
|
||||
|
||||
19
frontend-legacy/static/js/page/home.js
Normal file
19
frontend-legacy/static/js/page/home.js
Normal file
@@ -0,0 +1,19 @@
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.home;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
ccn_messagebox_Insert();
|
||||
ccn_messagebox_BindEvent();
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
});
|
||||
58
frontend-legacy/static/js/page/login.js
Normal file
58
frontend-legacy/static/js/page/login.js
Normal file
@@ -0,0 +1,58 @@
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.login;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
ccn_messagebox_Insert();
|
||||
ccn_messagebox_BindEvent();
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
|
||||
// bind login event
|
||||
$("#ccn-login-form-login").click(ccn_login_startLogin);
|
||||
});
|
||||
|
||||
function ccn_login_startLogin() {
|
||||
// disable all ui first
|
||||
$("#ccn-login-form-login").attr("disabled",true);
|
||||
$("#ccn-login-form-username").attr("disabled",true);
|
||||
$("#ccn-login-form-password").attr("disabled",true);
|
||||
|
||||
// get form data
|
||||
username = $("#ccn-login-form-username").val();
|
||||
password = $("#ccn-login-form-password").val();
|
||||
|
||||
/*
|
||||
// try get salt
|
||||
if (ccn_api_common_salt(username)) {
|
||||
// continue login
|
||||
if (ccn_api_common_login(username, password)) {
|
||||
// ok, logged
|
||||
// jump into home page again
|
||||
window.location.href = '/web/home';
|
||||
|
||||
} else ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-login"));
|
||||
} else ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-login"));
|
||||
*/
|
||||
if (ccn_api_common_webLogin(username, password)) {
|
||||
// ok, logged
|
||||
// jump into home page again
|
||||
window.location.href = '/web/home';
|
||||
return;
|
||||
|
||||
} else ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-login"));
|
||||
|
||||
// retore ui
|
||||
$("#ccn-login-form-login").removeAttr("disabled");
|
||||
$("#ccn-login-form-username").removeAttr("disabled");
|
||||
$("#ccn-login-form-password").removeAttr("disabled");
|
||||
}
|
||||
190
frontend-legacy/static/js/page/todo.js
Normal file
190
frontend-legacy/static/js/page/todo.js
Normal file
@@ -0,0 +1,190 @@
|
||||
var ccn_todo_todoListCache = [];
|
||||
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.todo;
|
||||
|
||||
// template process
|
||||
ccn_template_Load();
|
||||
|
||||
// nav process
|
||||
ccn_headerNav_Insert();
|
||||
ccn_headerNav_BindEvents();
|
||||
ccn_headerNav_LoggedRefresh();
|
||||
|
||||
// messagebox process
|
||||
ccn_messagebox_Insert();
|
||||
ccn_messagebox_BindEvent();
|
||||
|
||||
// apply i18n
|
||||
ccn_i18n_LoadLanguage();
|
||||
ccn_i18n_ApplyLanguage();
|
||||
|
||||
// refresh once
|
||||
ccn_todo_Refresh();
|
||||
|
||||
// bind event
|
||||
$("#ccn-todo-btnAdd").click(ccn_todo_Add);
|
||||
$("#ccn-todo-btnRefresh").click(ccn_todo_Refresh);
|
||||
});
|
||||
|
||||
function ccn_todo_RefreshCacheList() {
|
||||
// clean list cache first
|
||||
ccn_todo_todoListCache = new Array();
|
||||
|
||||
var result = ccn_api_todo_getFull();
|
||||
if(typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
ccn_todo_todoListCache[result[index][0]] = result[index];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ccn_todo_RenderCacheList() {
|
||||
// clean list first
|
||||
$("#ccn-todo-todoList").empty();
|
||||
|
||||
var renderdata = {
|
||||
uuid: undefined,
|
||||
data: undefined
|
||||
};
|
||||
|
||||
var listDOM = $("#ccn-todo-todoList");
|
||||
for(var index in ccn_todo_todoListCache) {
|
||||
// update render data
|
||||
var item = ccn_todo_todoListCache[index];
|
||||
renderdata.uuid = item[0];
|
||||
renderdata.data = LineBreaker2Br(item[2]);
|
||||
|
||||
// render
|
||||
listDOM.append(ccn_template_todoItem.render(renderdata));
|
||||
|
||||
// set mode
|
||||
var uuid = renderdata.uuid;
|
||||
ccn_todo_ChangeDisplayMode(uuid, false);
|
||||
|
||||
// bind event
|
||||
$("#ccn-todoItem-btnEdit-" + uuid).click(ccn_todo_ItemEdit);
|
||||
$("#ccn-todoItem-btnDelete-" + uuid).click(ccn_todo_ItemDelete);
|
||||
$("#ccn-todoItem-btnUpdate-" + uuid).click(ccn_todo_ItemUpdate);
|
||||
$("#ccn-todoItem-btnCancelUpdate-" + uuid).click(ccn_todo_ItemCancelUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_todo_ChangeDisplayMode(uuid, isEdit) {
|
||||
if(isEdit) {
|
||||
// 4 buttons
|
||||
$("#ccn-todoItem-btnEdit-" + uuid).hide();
|
||||
$("#ccn-todoItem-btnDelete-" + uuid).hide();
|
||||
$("#ccn-todoItem-btnUpdate-" + uuid).show();
|
||||
$("#ccn-todoItem-btnCancelUpdate-" + uuid).show();
|
||||
|
||||
// 2 elements
|
||||
$("#ccn-todoItem-p-" + uuid).hide();
|
||||
$("#ccn-todoItem-textarea-" + uuid).show();
|
||||
} else {
|
||||
$("#ccn-todoItem-btnEdit-" + uuid).show();
|
||||
$("#ccn-todoItem-btnDelete-" + uuid).show();
|
||||
$("#ccn-todoItem-btnUpdate-" + uuid).hide();
|
||||
$("#ccn-todoItem-btnCancelUpdate-" + uuid).hide();
|
||||
|
||||
$("#ccn-todoItem-p-" + uuid).show();
|
||||
$("#ccn-todoItem-textarea-" + uuid).hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ccn_todo_Refresh() {
|
||||
// refresh and render once
|
||||
ccn_todo_RefreshCacheList();
|
||||
ccn_todo_RenderCacheList();
|
||||
}
|
||||
|
||||
function ccn_todo_Add() {
|
||||
var result = ccn_api_todo_add();
|
||||
if (typeof(result) == 'undefined') {
|
||||
// fail
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-add"));
|
||||
} else {
|
||||
// add into cache
|
||||
ccn_todo_todoListCache[result[0]] = result;
|
||||
|
||||
// render
|
||||
var listDOM = $("#ccn-todo-todoList");
|
||||
listDOM.append(ccn_template_todoItem.render({
|
||||
uuid: result[0],
|
||||
data: LineBreaker2Br(result[2])
|
||||
}));
|
||||
|
||||
// set mode
|
||||
var uuid = result[0];
|
||||
ccn_todo_ChangeDisplayMode(uuid, false);
|
||||
|
||||
// bind event
|
||||
$("#ccn-todoItem-btnEdit-" + uuid).click(ccn_todo_ItemEdit);
|
||||
$("#ccn-todoItem-btnDelete-" + uuid).click(ccn_todo_ItemDelete);
|
||||
$("#ccn-todoItem-btnUpdate-" + uuid).click(ccn_todo_ItemUpdate);
|
||||
$("#ccn-todoItem-btnCancelUpdate-" + uuid).click(ccn_todo_ItemCancelUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_todo_ItemEdit() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
// copy current data to textarea
|
||||
$("#ccn-todoItem-textarea-" + uuid).val(
|
||||
ccn_todo_todoListCache[uuid][2]
|
||||
);
|
||||
|
||||
// switch to edit mode
|
||||
ccn_todo_ChangeDisplayMode(uuid, true);
|
||||
}
|
||||
|
||||
function ccn_todo_ItemDelete() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
var result = ccn_api_todo_delete(
|
||||
uuid,
|
||||
ccn_todo_todoListCache[uuid][3]
|
||||
);
|
||||
|
||||
if(!result) {
|
||||
// fail
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-delete"));
|
||||
} else {
|
||||
// remove body
|
||||
$("#ccn-todoItem-" + uuid).remove();
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_todo_ItemUpdate() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
var newData = $("#ccn-todoItem-textarea-" + uuid).val();
|
||||
var result = ccn_api_todo_update(
|
||||
uuid,
|
||||
newData,
|
||||
ccn_todo_todoListCache[uuid][3]
|
||||
);
|
||||
|
||||
if (typeof(result) == 'undefined') {
|
||||
// fail
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-update"));
|
||||
} else {
|
||||
// safely update data & lastChanged and control
|
||||
ccn_todo_todoListCache[uuid][2] = newData;
|
||||
ccn_todo_todoListCache[uuid][3] = result;
|
||||
$("#ccn-todoItem-p-" + uuid).html(LineBreaker2Br(newData));
|
||||
|
||||
// switch to normal mode
|
||||
ccn_todo_ChangeDisplayMode(uuid, false);
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_todo_ItemCancelUpdate() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
// clean data
|
||||
$("#ccn-todoItem-textarea-" + uuid).val("");
|
||||
// switch to normal mode
|
||||
ccn_todo_ChangeDisplayMode(uuid, false);
|
||||
}
|
||||
Reference in New Issue
Block a user