2022-08-16 16:46:14 -05:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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();
|
2022-08-23 13:41:21 -05:00
|
|
|
let shared = $("#isShared").prop('checked');
|
2022-08-16 16:46:14 -05:00
|
|
|
|
|
|
|
|
if (listName == null || listName == "") {
|
|
|
|
|
Session.set("listNameMiss", true);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2022-08-23 13:41:21 -05:00
|
|
|
Meteor.call('add.list', listName, shared, function(err, result) {
|
2022-08-16 16:46:14 -05:00
|
|
|
if (err) {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" ERROR adding list name: " + err);
|
2022-08-16 16:46:14 -05:00
|
|
|
} else {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" SUCCESS adding list name.");
|
2022-08-16 16:46:14 -05:00
|
|
|
$("#listNameInp").val("");
|
2022-08-23 13:41:21 -05:00
|
|
|
$("#isShared").prop("checked", false);
|
2022-08-16 16:46:14 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'click .renameListMgmt' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
let listName = $("#listNameInp").val();
|
2022-08-23 13:41:21 -05:00
|
|
|
let shared = $("#isShared").prop('checked');
|
2022-08-16 16:46:14 -05:00
|
|
|
let listId = Session.get("listItemId");
|
|
|
|
|
|
|
|
|
|
if (listName == null || listName == "") {
|
|
|
|
|
Session.set("listNameMiss", true);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2022-08-23 13:41:21 -05:00
|
|
|
Meteor.call('edit.list', listId, listName, shared, function(err, result) {
|
2022-08-16 16:46:14 -05:00
|
|
|
if (err) {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" ERROR editing list name: " + err);
|
2022-08-16 16:46:14 -05:00
|
|
|
} else {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" SUCCESS editing list name.");
|
2022-08-16 16:46:14 -05:00
|
|
|
$("#listNameInp").val("");
|
2022-08-23 13:41:21 -05:00
|
|
|
$("#isShared").prop("checked", false);
|
2022-08-16 16:46:14 -05:00
|
|
|
Session.set("listNameEditMode", false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'submit .listAdd' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
let editMode = Session.get("listNameEditMode");
|
2022-08-23 13:41:21 -05:00
|
|
|
let shared = $("#isShared").prop("checked");
|
2022-08-16 16:46:14 -05:00
|
|
|
let listName = $("#listNameInp").val();
|
|
|
|
|
let listId = Session.get("listItemId");
|
|
|
|
|
|
|
|
|
|
if (listName == null || listName == "") {
|
|
|
|
|
Session.set("listNameMiss", true);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
if (editMode == false) {
|
2022-08-23 13:41:21 -05:00
|
|
|
Meteor.call('add.list', listName, shared, function(err, result) {
|
2022-08-16 16:46:14 -05:00
|
|
|
if (err) {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" ERROR adding list name: " + err);
|
2022-08-16 16:46:14 -05:00
|
|
|
} else {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" SUCCESS adding list name.");
|
2022-08-16 16:46:14 -05:00
|
|
|
$("#listNameInp").val("");
|
2022-08-23 13:41:21 -05:00
|
|
|
$("#isShared").prop("checked", false);
|
2022-08-16 16:46:14 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2022-08-23 13:41:21 -05:00
|
|
|
Meteor.call('edit.list', listId, listName, shared, function(err, result) {
|
2022-08-16 16:46:14 -05:00
|
|
|
if (err) {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" ERROR editing list name: " + err);
|
2022-08-16 16:46:14 -05:00
|
|
|
} else {
|
2022-08-26 11:18:18 -05:00
|
|
|
// console.log(" SUCCESS editing list name.");
|
2022-08-16 16:46:14 -05:00
|
|
|
$("#listNameInp").val("");
|
2022-08-23 13:41:21 -05:00
|
|
|
$("#isShared").prop("checked", false);
|
2022-08-16 16:46:14 -05:00
|
|
|
Session.set("listNameEditMode", false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|