1
0
Files
coconut-leaf/src/static/js/page/calendar.js

395 lines
13 KiB
JavaScript
Raw Normal View History

2021-02-03 20:50:02 +08:00
// 3 used cache list
2021-02-05 17:07:20 +08:00
var ccn_calendar_owned_listCache = [];
var ccn_calendar_sharing_listCache = [];
var ccn_calendar_shared_listCache = [];
2021-02-03 16:08:40 +08:00
2021-02-03 20:50:02 +08:00
// current editing sharing collection
2021-02-05 17:07:20 +08:00
var ccn_calendar_sharing_editingOwned = undefined; // the uuid of owned collection
2021-02-03 20:50:02 +08:00
// 2 list which will store sharing and shared collection's display mode.
// key is uuid, value is bool
var ccn_calendar_sharing_displayCache = [];
var ccn_calendar_shared_displayCache = [];
2021-01-19 22:20:11 +08:00
$(document).ready(function() {
ccn_pages_currentPage = ccn_pages_enumPages.calendar;
2021-01-24 14:38:08 +08:00
// template process
ccn_template_Load();
// nav process
2021-01-30 17:30:28 +08:00
ccn_headerNav_Insert();
ccn_headerNav_BindEvents();
ccn_headerNav_LoggedRefresh();
2021-01-19 22:20:11 +08:00
2021-01-30 17:30:28 +08:00
// messagebox process
ccn_messagebox_Insert();
ccn_messagebox_BindEvent();
2021-01-19 22:20:11 +08:00
// process calendar it self
ccn_calendar_LoadCalendarBody();
2021-01-23 18:37:12 +08:00
// 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);
2021-01-19 22:20:11 +08:00
// apply i18n
2021-02-03 16:08:40 +08:00
ccn_i18n_LoadLanguage();
2021-01-19 22:20:11 +08:00
ccn_i18n_ApplyLanguage();
2021-02-04 16:32:42 +08:00
2021-02-05 17:07:20 +08:00
//refresh once
ccn_calendar_shared_Refresh();
ccn_calendar_owned_Refresh();
2021-02-04 16:32:42 +08:00
// bind event
$('#ccn-calendar-shared-btnRefresh').click(ccn_calendar_shared_Refresh);
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-owned-btnAdd').click(ccn_calendar_owned_Add);
$('#ccn-calendar-own-btnRefresh').click(ccn_calendar_owned_Refresh);
$('#ccn-calendar-sharing-btnAdd').click(ccn_calendar_sharing_Add);
2021-02-04 16:32:42 +08:00
$('#ccn-calendar-sharing-btnRefresh').click(ccn_calendar_sharing_Refresh);
2021-01-19 22:20:11 +08:00
});
2021-02-04 16:32:42 +08:00
// ================== calendar
2021-01-19 22:20:11 +08:00
function ccn_calendar_LoadCalendarBody() {
2021-01-25 20:42:06 +08:00
$('#ccn-calendar-calendarBbody').append(ccn_template_calendarItem.render());
2021-01-19 22:20:11 +08:00
}
2021-02-03 16:08:40 +08:00
// ================== collection
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_Refresh() {
ccn_calendar_owned_listCache = new Array();
2021-02-03 20:50:02 +08:00
ccn_calendar_sharing_displayCache = new Array();
2021-02-03 16:08:40 +08:00
var result = ccn_api_collection_getFullOwn();
if(typeof(result) != 'undefined') {
for(var index in result) {
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[result[index][0]] = result[index];
2021-02-03 20:50:02 +08:00
ccn_calendar_sharing_displayCache[result[index][0]] = true;
2021-02-03 16:08:40 +08:00
}
}
// render
2021-02-05 17:07:20 +08:00
var listDOM = $('#ccn-calendar-ownedList');
listDOM.empty();
for(var index in ccn_calendar_owned_listCache) {
ccn_calendar_owned_RenderItem(
ccn_calendar_owned_listCache[index],
2021-02-03 16:08:40 +08:00
listDOM
)
}
2021-02-05 17:07:20 +08:00
// also, order sharing list clean
ccn_calendar_sharing_editingOwned = undefined;
ccn_calendar_sharing_Refresh();
2021-02-03 16:08:40 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_RenderItem(item, listDOM) {
2021-02-03 20:50:02 +08:00
var renderdata = {
uuid: item[0],
name: item[1]
}
// render
2021-02-05 17:07:20 +08:00
listDOM.append(ccn_template_ownedItem.render(renderdata));
2021-02-03 20:50:02 +08:00
// set mode
var uuid = renderdata.uuid;
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_ChangeDisplayMode(uuid, true, false);
2021-02-03 20:50:02 +08:00
// bind event
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnEdit-' + uuid).click(ccn_calendar_owned_ItemEdit);
$('#ccn-calendar-ownedItem-btnDelete-' + uuid).click(ccn_calendar_owned_ItemDelete);
$('#ccn-calendar-ownedItem-btnShare-' + uuid).click(ccn_calendar_owned_ItemShare);
$('#ccn-calendar-ownedItem-btnHide-' + uuid).click(ccn_calendar_owned_ItemSwitchDisplay);
$('#ccn-calendar-ownedItem-btnShow-' + uuid).click(ccn_calendar_owned_ItemSwitchDisplay);
$('#ccn-calendar-ownedItem-btnUpdate-' + uuid).click(ccn_calendar_owned_ItemUpdate);
$('#ccn-calendar-ownedItem-btnCancelUpdate-' + uuid).click(ccn_calendar_owned_ItemCancelUpdate);
2021-02-03 16:08:40 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ChangeDisplayMode(uuid, isShow, isEdit) {
2021-02-03 20:50:02 +08:00
if (typeof(isShow) != 'undefined') {
if (isShow) {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnHide-' + uuid).show();
$('#ccn-calendar-ownedItem-btnShow-' + uuid).hide();
2021-02-03 20:50:02 +08:00
} else {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnHide-' + uuid).hide();
$('#ccn-calendar-ownedItem-btnShow-' + uuid).show();
2021-02-03 20:50:02 +08:00
}
}
if (typeof(isEdit) != 'undefined') {
if (isEdit) {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnEdit-' + uuid).hide();
$('#ccn-calendar-ownedItem-btnShare-' + uuid).hide();
$('#ccn-calendar-ownedItem-btnDelete-' + uuid).hide();
2021-02-03 20:50:02 +08:00
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnUpdate-' + uuid).show();
$('#ccn-calendar-ownedItem-btnCancelUpdate-' + uuid).show();
2021-02-03 20:50:02 +08:00
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-textName-' + uuid).hide();
$('#ccn-calendar-ownedItem-boxName-' + uuid).show();
2021-02-03 20:50:02 +08:00
} else {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnEdit-' + uuid).show();
$('#ccn-calendar-ownedItem-btnShare-' + uuid).show();
$('#ccn-calendar-ownedItem-btnDelete-' + uuid).show();
2021-02-03 20:50:02 +08:00
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-btnUpdate-' + uuid).hide();
$('#ccn-calendar-ownedItem-btnCancelUpdate-' + uuid).hide();
2021-02-03 20:50:02 +08:00
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-textName-' + uuid).show();
$('#ccn-calendar-ownedItem-boxName-' + uuid).hide();
2021-02-03 20:50:02 +08:00
}
}
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_sharing_Refresh() {
ccn_calendar_sharing_listCache = new Array();
2021-02-03 20:50:02 +08:00
2021-02-05 17:07:20 +08:00
if (typeof(ccn_calendar_sharing_editingOwned) != 'undefined') {
var result = ccn_api_collection_getSharing(ccn_calendar_sharing_editingOwned);
2021-02-03 20:50:02 +08:00
if (typeof(result) != 'undefined') {
for(var index in result) {
2021-02-05 17:07:20 +08:00
ccn_calendar_sharing_listCache[index] = result[index];
2021-02-03 20:50:02 +08:00
// also, sharingTarget don't have uuid, use index instead
}
}
}
2021-02-03 16:08:40 +08:00
2021-02-05 17:07:20 +08:00
// update editing text
$('#ccn-calendar-sharing-sharingEditing').text(
typeof(ccn_calendar_sharing_editingOwned) == 'undefined' ?
'' :
ccn_calendar_owned_listCache[ccn_calendar_sharing_editingOwned][1]
);
// if editing is undefined, hide container
if (typeof(ccn_calendar_sharing_editingOwned) == 'undefined')
$('#ccn-calendar-sharing-container').hide();
else
$('#ccn-calendar-sharing-container').show();
var listDOM = $('#ccn-calendar-sharingList');
2021-02-03 20:50:02 +08:00
listDOM.empty();
2021-02-05 17:07:20 +08:00
for(var index in ccn_calendar_sharing_listCache) {
ccn_calendar_sharing_RenderItem(
ccn_calendar_sharing_listCache[index],
2021-02-03 20:50:02 +08:00
index,
listDOM
)
}
2021-02-03 16:08:40 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_sharing_RenderItem(item, index, listDOM) {
2021-02-03 20:50:02 +08:00
var renderdata = {
uuid: index,
username: item
}
// render
2021-02-05 17:07:20 +08:00
listDOM.append(ccn_template_sharingItem.render(renderdata));
2021-02-03 20:50:02 +08:00
// bind event
var uuid = index;
2021-02-05 17:07:20 +08:00
$("#ccn-calendar-sharingItem-btnDelete-" + uuid).click(ccn_calendar_sharing_ItemDelete);
2021-02-03 16:08:40 +08:00
}
2021-02-03 20:50:02 +08:00
2021-02-03 16:08:40 +08:00
function ccn_calendar_shared_Refresh() {
2021-02-05 17:07:20 +08:00
ccn_calendar_shared_listCache = new Array();
2021-02-03 20:50:02 +08:00
ccn_calendar_shared_displayCache = new Array();
2021-02-03 16:08:40 +08:00
2021-02-03 20:50:02 +08:00
var result = ccn_api_collection_getShared();
if (typeof(result) != 'undefined') {
for(var index in result) {
2021-02-05 17:07:20 +08:00
ccn_calendar_shared_listCache[result[index][0]] = result[index];
2021-02-03 20:50:02 +08:00
ccn_calendar_shared_displayCache[result[index][0]] = true;
}
}
var renderdata = {
uuid: undefined,
name: undefined,
username: undefined
}
var listDOM = $('#ccn-calendar-sharedList');
listDOM.empty();
2021-02-05 17:07:20 +08:00
for(var index in ccn_calendar_shared_listCache) {
var item = ccn_calendar_shared_listCache[index];
2021-02-03 20:50:02 +08:00
renderdata.uuid = item[0];
renderdata.name = item[1];
renderdata.username = item[2];
listDOM.append(ccn_template_sharedItem.render(renderdata));
2021-02-05 17:07:20 +08:00
// change display
2021-02-03 20:50:02 +08:00
var uuid = renderdata.uuid;
2021-02-05 17:07:20 +08:00
ccn_calendar_shared_ChangeDisplayMode(uuid, true);
// bind event
$('#ccn-calendar-sharedItem-btnHide-' + uuid).click(ccn_calendar_shared_ItemSwitchDisplay);
$('#ccn-calendar-sharedItem-btnShow-' + uuid).click(ccn_calendar_shared_ItemSwitchDisplay);
2021-02-03 20:50:02 +08:00
}
ccn_i18n_ApplyLanguage2Content(listDOM);
}
function ccn_calendar_shared_ChangeDisplayMode(uuid, isShow) {
if (isShow) {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-sharedItem-btnHide-' + uuid).show();
$('#ccn-calendar-sharedItem-btnShow-' + uuid).hide();
2021-02-03 20:50:02 +08:00
} else {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-sharedItem-btnHide-' + uuid).hide();
$('#ccn-calendar-sharedItem-btnShow-' + uuid).show();
2021-02-03 20:50:02 +08:00
}
}
// ========================= input operation
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_Add() {
var newname = $('#ccn-calendar-owned-inputAdd').val();
2021-02-04 16:32:42 +08:00
if (newname == "") return;
var result = ccn_api_collection_addOwn(newname);
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-js-fail-add"));
else {
// second get. get detail
result = ccn_api_collection_getDetailOwn(result);
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-js-fail-get"));
else {
// render
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[result[0]] = result;
var listDOM = $('#ccn-calendar-ownedList');
ccn_calendar_owned_RenderItem(result, listDOM);
2021-02-04 16:32:42 +08:00
}
}
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ItemEdit() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
// preset inputbox
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-inputName-' + uuid).val(
ccn_calendar_owned_listCache[uuid][1]
2021-02-04 16:32:42 +08:00
);
2021-02-03 20:50:02 +08:00
2021-02-04 16:32:42 +08:00
// switch to edit mode
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_ChangeDisplayMode(uuid, undefined, true);
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ItemDelete() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
var result = ccn_api_collection_deleteOwn(
uuid,
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[uuid][2]
2021-02-04 16:32:42 +08:00
);
if (!result) ccn_messagebox_Show($.i18n.prop("ccn-js-fail-delete"));
else {
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-' + uuid).remove();
2021-02-04 16:32:42 +08:00
// also, we should notice sharing target, and try clean it
2021-02-05 17:07:20 +08:00
if (ccn_calendar_sharing_editingOwned == uuid) {
ccn_calendar_sharing_editingOwned = undefined;
ccn_calendar_sharing_Refresh();
2021-02-04 16:32:42 +08:00
}
}
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ItemUpdate() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
2021-02-05 17:07:20 +08:00
var newname = $('#ccn-calendar-ownedItem-inputName-' + uuid).val();
2021-02-04 16:32:42 +08:00
2021-02-05 17:07:20 +08:00
var result = ccn_api_collection_updateOwn(uuid, newname, ccn_calendar_owned_listCache[uuid][2]);
2021-02-04 16:32:42 +08:00
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-js-fail-update"));
else {
// update last change
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[uuid][2] = result;
ccn_calendar_owned_listCache[uuid][1] = newname;
2021-02-04 16:32:42 +08:00
// update elements
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-ownedItem-textName-' + uuid).text(newname);
2021-02-04 16:32:42 +08:00
// if editing, update sharing target
2021-02-05 17:07:20 +08:00
if (ccn_calendar_sharing_editingOwned == uuid)
ccn_calendar_sharing_Refresh();
2021-02-04 16:32:42 +08:00
// back to normal mode
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_ChangeDisplayMode(uuid, undefined, false);
2021-02-04 16:32:42 +08:00
}
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ItemCancelUpdate() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_ChangeDisplayMode(uuid, undefined, false);
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ItemSwitchDisplay() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
ccn_calendar_sharing_displayCache[uuid] = !(ccn_calendar_sharing_displayCache[uuid]);
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_ChangeDisplayMode(uuid, ccn_calendar_sharing_displayCache[uuid], undefined);
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_owned_ItemShare() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
2021-02-05 17:07:20 +08:00
ccn_calendar_sharing_editingOwned = uuid;
ccn_calendar_sharing_Refresh();
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_sharing_Add() {
var newusername = $('#ccn-calendar-sharing-inputAdd').val();
if (newusername == "" || typeof(ccn_calendar_sharing_editingOwned) == 'undefined') return;
2021-02-04 16:32:42 +08:00
var result = ccn_api_collection_addSharing(
2021-02-05 17:07:20 +08:00
ccn_calendar_sharing_editingOwned,
2021-02-04 16:32:42 +08:00
newusername,
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[ccn_calendar_sharing_editingOwned][2]
2021-02-04 16:32:42 +08:00
);
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-js-fail-add"));
else {
// add new item
2021-02-05 17:07:20 +08:00
var index = ccn_calendar_sharing_listCache.push(newusername) - 1;
var listDOM = $('#ccn-calendar-sharingList');
ccn_calendar_sharing_RenderItem(newusername, index, listDOM);
2021-02-04 16:32:42 +08:00
// update last change
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[ccn_calendar_sharing_editingOwned][2] = result;
2021-02-04 16:32:42 +08:00
}
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_sharing_ItemDelete() {
2021-02-04 16:32:42 +08:00
var uuid = $(this).attr("uuid");
2021-02-05 17:07:20 +08:00
var username = ccn_calendar_sharing_listCache[uuid];
2021-02-04 16:32:42 +08:00
var result = ccn_api_collection_deleteSharing(
2021-02-05 17:07:20 +08:00
ccn_calendar_sharing_editingOwned,
2021-02-04 16:32:42 +08:00
username,
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[ccn_calendar_sharing_editingOwned][2]
2021-02-04 16:32:42 +08:00
);
if (typeof(result) == 'undefined') ccn_messagebox_Show($.i18n.prop("ccn-js-fail-delete"));
else {
// remove item in ui
2021-02-05 17:07:20 +08:00
$('#ccn-calendar-sharingItem-' + uuid).remove();
2021-02-04 16:32:42 +08:00
// update last change
2021-02-05 17:07:20 +08:00
ccn_calendar_owned_listCache[ccn_calendar_sharing_editingOwned][2] = result;
2021-02-04 16:32:42 +08:00
}
2021-02-03 20:50:02 +08:00
}
2021-02-05 17:07:20 +08:00
function ccn_calendar_shared_ItemSwitchDisplay() {
2021-02-04 16:32:42 +08:00
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]);
2021-02-03 16:08:40 +08:00
}