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

541 lines
18 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-02-07 21:12:56 +08:00
// modal editing object.
// undefined mean add
// not undefined mean update
var ccn_calendar_eventModal_editing = undefined;
var ccn_calendar_calendar_listCache = [];
var ccn_calendar_calendar_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
2021-02-07 21:12:56 +08:00
ccn_calendar_calendar_LoadCalendarBody();
2021-01-19 22:20:11 +08:00
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-02-07 21:12:56 +08:00
// init datetimepicker
ccn_calendar_datetimepicker_Init();
// init span picker
$('.spanpicker').attr('max', 100)
.attr('min', 1)
.attr('step', 1)
.val(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);
2021-02-07 21:12:56 +08:00
$('#ccn-calendar-owned-btnRefresh').click(ccn_calendar_owned_Refresh);
2021-02-05 17:07:20 +08:00
$('#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-02-07 21:12:56 +08:00
$('#ccn-calendar-calendar-btnJump').click(ccn_calendar_calendar_Refresh);
$('#ccn-calendar-calendar-btnToday').click(ccn_calendar_calendar_Today);
$('#ccn-calendar-calendar-btnAdd').click(ccn_calendar_calendar_Add);
$('#ccn-calendar-modalEvent-btnSubmit').click(ccn_calendar_calendar_ItemUpdate);
$('#ccn-calendar-modalEvent-btnCancel').click(ccn_calendar_calendar_ItemCancel);
$('#ccn-calendar-modalEvent-btnClose').click(ccn_calendar_calendar_ItemCancel);
2021-01-19 22:20:11 +08:00
});
2021-02-07 21:12:56 +08:00
// ================== assist func
function ccn_calendar_datetimepicker_Init() {
var nowtime = new Date();
$('.datetimepicker-year').attr('min', ccn_datetime_MIN_YEAR)
.attr('max', ccn_datetime_MAX_YEAR)
.attr('step', 1)
.val(nowtime.getFullYear())
.bind('propertychange', ccn_calendar_datetimepicker_Sync);
$('.datetimepicker-month').attr('min', 1)
.attr('max', 12)
.attr('step', 1)
.val(nowtime.getMonth() + 1)
.bind('propertychange', ccn_calendar_datetimepicker_Sync);
$('.datetimepicker-day').attr('min', 1)
.attr('step', 1)
.each(function(){
ccn_calendar_datetimepicker_SyncEx($(this).attr("datetimepicker"));
})
.val(nowtime.getDate());
$('.datetimepicker-hour').attr('min', 0)
.attr('max', 23)
.attr('step', 1)
.val(nowtime.getHours());
$('.datetimepicker-minute').attr('min', 0)
.attr('max', 59)
.attr('step', 1)
.val(nowtime.getMinutes());
}
function ccn_calendar_datetimepicker_Sync() {
var pickerIndex = $(this).attr("datetimepicker");
ccn_calendar_datetimepicker_SyncEx(pickerIndex);
}
function ccn_calendar_datetimepicker_SyncEx(pickerIndex) {
year = $('.datetimepicker-year[datetimepicker=' + pickerIndex + ']').val();
month = $('.datetimepicker-month[datetimepicker=' + pickerIndex + ']').val();
dayDOM = $('.datetimepicker-day[datetimepicker=' + pickerIndex + ']');
if (typeof(year) == 'undefined' || typeof(month) == 'undefined') {
dayDOM.attr('max', 1)
.val(1);
} else {
dayDOM.attr('max', ccn_datetime_monthDayCount[month - 1] + ((month == 2 && ccn_datetime_IsLeapYear(year) ? 1 : 0)))
.val(1);
}
}
function ccn_calendar_datetimepicker_Set(pickerIndex, dt) {
$('.datetimepicker-year[datetimepicker=' + pickerIndex + ']').val(dt.getFullYear());
$('.datetimepicker-month[datetimepicker=' + pickerIndex + ']').val(dt.getMonth() + 1);
$('.datetimepicker-day[datetimepicker=' + pickerIndex + ']').val(dt.getDate());
$('.datetimepicker-hour[datetimepicker=' + pickerIndex + ']').val(dt.getHours());
$('.datetimepicker-minute[datetimepicker=' + pickerIndex + ']').val(dt.getMinutes());
}
function ccn_calendar_datetimepicker_Get(pickerIndex) {
year = $('.datetimepicker-year[datetimepicker=' + pickerIndex + ']').val();
month = $('.datetimepicker-month[datetimepicker=' + pickerIndex + ']').val();
day = $('.datetimepicker-day[datetimepicker=' + pickerIndex + ']').val();
hour = $('.datetimepicker-hour[datetimepicker=' + pickerIndex + ']').val();
minute = $('.datetimepicker-minute[datetimepicker=' + pickerIndex + ']').val();
if (IsUndefinedOrEmpty(year)) year = ccn_datetime_MIN_YEAR;
if (IsUndefinedOrEmpty(month)) month = 1;
if (IsUndefinedOrEmpty(day)) day = 1;
if (IsUndefinedOrEmpty(hour)) hour = 0;
if (IsUndefinedOrEmpty(minute)) minute = 0;
return new Date(year, month - 1, day, hour, minute, 0, 0);
}
2021-02-04 16:32:42 +08:00
// ================== calendar
2021-02-07 21:12:56 +08:00
function ccn_calendar_calendar_LoadCalendarBody() {
$('#ccn-calendar-calendarBody').append(ccn_template_calendarItem.render());
}
function ccn_calendar_calendar_Refresh() {
gottenDateTime = ccn_calendar_datetimepicker_Get(4);
gottenYear = gottenDateTime.getFullYear();
gottenMonth = gottenDateTime.getMonth() + 1;
}
function ccn_calendar_calendar_Render() {
}
function ccn_calendar_calendar_AnalyseEvent() {
}
function ccn_calendar_calendar_Today() {
var nowtime = new Date();
ccn_calendar_datetimepicker_Set(4, nowtime);
ccn_calendar_calendar_Refresh();
}
function ccn_calendar_calendar_Add() {
$('#ccn-calendar-modalEvent').addClass('is-active');
}
function ccn_calendar_calendar_ItemEdit() {
$('#ccn-calendar-modalEvent').addClass('is-active');
}
function ccn_calendar_calendar_ItemUpdate() {
$('#ccn-calendar-modalEvent').removeClass('is-active');
}
function ccn_calendar_calendar_ItemCancel() {
$('#ccn-calendar-modalEvent').removeClass('is-active');
}
function ccn_calendar_calendar_DeployEventModal() {
}
// return undefined to indicate an error
function ccn_calendar_calendar_GetEventModal() {
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
}