mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
92 lines
No EOL
2.7 KiB
JavaScript
92 lines
No EOL
2.7 KiB
JavaScript
import { Lists } from '../../../imports/api/lists.js';
|
|
|
|
Template.listMgmtForm.onCreated(function() {
|
|
this.subscribe("myLists");
|
|
});
|
|
|
|
Template.listMgmtForm.onRendered(function() {
|
|
Session.set("listNameMiss", false);
|
|
Session.set("listNameEditMode", false);
|
|
Session.set("showCompletedLists", false);
|
|
});
|
|
|
|
Template.listMgmtForm.helpers({
|
|
listNameErr: function() {
|
|
return Session.get("listNameMiss");
|
|
},
|
|
editMode: function() {
|
|
return Session.get("listNameEditMode");
|
|
}
|
|
});
|
|
|
|
Template.listMgmtForm.events({
|
|
'click .saveListMgmt' (event) {
|
|
event.preventDefault();
|
|
let listName = $("#listNameInp").val();
|
|
let shared = $("#isShared").prop('checked');
|
|
|
|
if (listName == null || listName == "") {
|
|
Session.set("listNameMiss", true);
|
|
return;
|
|
} else {
|
|
addList(listName, shared);
|
|
}
|
|
},
|
|
'click .renameListMgmt' (event) {
|
|
event.preventDefault();
|
|
let listName = $("#listNameInp").val();
|
|
let shared = $("#isShared").prop('checked');
|
|
let listId = Session.get("listItemId");
|
|
|
|
if (listName == null || listName == "") {
|
|
Session.set("listNameMiss", true);
|
|
return;
|
|
} else {
|
|
editList(listId, listName, shared);
|
|
}
|
|
},
|
|
'submit .listAdd' (event) {
|
|
event.preventDefault();
|
|
let editMode = Session.get("listNameEditMode");
|
|
let shared = $("#isShared").prop("checked");
|
|
let listName = $("#listNameInp").val();
|
|
let listId = Session.get("listItemId");
|
|
|
|
if (listName == null || listName == "") {
|
|
Session.set("listNameMiss", true);
|
|
return;
|
|
} else {
|
|
if (editMode == false) {
|
|
addList(listName, shared);
|
|
} else {
|
|
editList(listId, listName, shared);
|
|
}
|
|
}
|
|
},
|
|
'change #isCompleted' (event) {
|
|
Session.set("showCompletedLists", true);
|
|
},
|
|
});
|
|
|
|
const addList = async(listName, shared) => {
|
|
let result = await Meteor.callAsync('add.list', listName, shared);
|
|
if (!result) {
|
|
// console.log(" ERROR adding list name: ");
|
|
} else {
|
|
// console.log(" SUCCESS adding list name.");
|
|
$("#listNameInp").val("");
|
|
$("#isShared").prop("checked", false);
|
|
}
|
|
}
|
|
|
|
const editList = async(listId, listName, shared) => {
|
|
let result = await Meteor.callAsync('edit.list', listId, listName, shared);
|
|
if (!result) {
|
|
// console.log(" ERROR editing list name: " + err);
|
|
} else {
|
|
// console.log(" SUCCESS editing list name.");
|
|
$("#listNameInp").val("");
|
|
$("#isShared").prop("checked", false);
|
|
Session.set("listNameEditMode", false);
|
|
}
|
|
} |