diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index db3a436..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-Stratusolve-Exercise
\ No newline at end of file
diff --git a/.idea/Stratusolve-Exercise.iml b/.idea/Stratusolve-Exercise.iml
index b313593..c956989 100644
--- a/.idea/Stratusolve-Exercise.iml
+++ b/.idea/Stratusolve-Exercise.iml
@@ -4,15 +4,5 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
deleted file mode 100644
index e7bedf3..0000000
--- a/.idea/copyright/profiles_settings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8bd72f9..38b0a22 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,12 +1,11 @@
-
+
+
+
-
-
-
@@ -14,20 +13,14 @@
-
-
-
-
-
-
-
+
@@ -36,30 +29,41 @@
-
-
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -73,9 +77,10 @@
@@ -85,15 +90,15 @@
true
DEFINITION_ORDER
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
@@ -117,6 +122,10 @@
+
+
+
+
@@ -125,16 +134,49 @@
-
-
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -146,75 +188,97 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
project
-
-
-
+
+ true
+
+
+ DIRECTORY
+
+ false
+
+
+
+
+
+
+
+
+
+
+
-
- 1463122043916
+
+ 1517556772704
- 1463122043916
-
-
+ 1517556772704
+
+
-
+
-
+
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -223,101 +287,105 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/Task_Data.txt b/Task_Data.txt
index eb99a7e..f8f7c74 100644
--- a/Task_Data.txt
+++ b/Task_Data.txt
@@ -1 +1 @@
-[{"TaskId":1,"TaskName":"Test","TaskDescription":"Test"},{"TaskId":"2","TaskName":"Test2","TaskDescription":"Test2"}]
\ No newline at end of file
+{"5":{"TaskId":6,"TaskName":"Task 1","TaskDescription":"Testing if it will save accordingly"},"6":{"TaskId":7,"TaskName":"Task 2","TaskDescription":"Testing if update and delete work correctly"},"7":{"TaskId":8,"TaskName":"Task 4","TaskDescription":"Testing resetting of field values"},"8":{"TaskId":9,"TaskName":"Task 3","TaskDescription":"Testing adding again to see if the changes will work just fine"},"9":{"TaskId":10,"TaskName":"Task 5","TaskDescription":"Testing without the closing php tag"},"10":{"TaskId":11,"TaskName":"Task 6","TaskDescription":"Surely now everything works accordingly? "}}
\ No newline at end of file
diff --git a/index.php b/index.php
index f04b68d..8ac23dd 100644
--- a/index.php
+++ b/index.php
@@ -78,31 +78,78 @@
if (triggerElement.attr("id") == 'newTask') {
modal.find('.modal-title').text('New Task');
$('#deleteTask').hide();
+ setFieldValues();
currentTaskId = -1;
} else {
modal.find('.modal-title').text('Task details');
$('#deleteTask').show();
currentTaskId = triggerElement.attr("id");
+ var taskNameElement = triggerElement.find('h4');
+ var taskDescriptionElement = triggerElement.find('p');
+
+ setFieldValues($(taskNameElement).text(), $(taskDescriptionElement).text());
+
console.log('Task ID: '+triggerElement.attr("id"));
}
});
+
+ var setFieldValues = function(taskName, taskDescription) {
+ if (taskName === undefined) {
+ taskName = "";
+ }
+ if (taskDescription === undefined) {
+ taskDescription = "";
+ }
+ $("#InputTaskName").val(taskName);
+ $("#InputTaskDescription").val(taskDescription);
+ };
+
+ var handleSubmission = function(path, data) {
+ $.post(path, data, function (feedback) {
+ var message = feedback.message;
+ var messageClass = 'alert alert-danger';
+ if (feedback.success) {
+ messageClass = 'alert alert-success';
+ updateTaskList();
+ }
+
+ var messageBox = $('' + message + '
');
+
+ $(".modal-body form").prepend(messageBox);
+ setTimeout(function() {
+ $("#feedback-message").remove();
+ setFieldValues();
+ $('#myModal').modal('hide');
+ }, 3000);
+
+ }, 'json');
+ };
+
$('#saveTask').click(function() {
//Assignment: Implement this functionality
- alert('Save... Id:'+currentTaskId);
- $('#myModal').modal('hide');
- updateTaskList();
+ //alert('Save... Id:'+currentTaskId);
+
+ var taskName = $("#InputTaskName").val();
+ var taskDescription = $("#InputTaskDescription").val();
+
+ var data = {task_id:currentTaskId, task_name:taskName, task_description:taskDescription, action:'save'};
+ handleSubmission('update_task.php', data)
});
+
$('#deleteTask').click(function() {
//Assignment: Implement this functionality
- alert('Delete... Id:'+currentTaskId);
- $('#myModal').modal('hide');
- updateTaskList();
+ //alert('Delete... Id:'+currentTaskId);
+
+ var data = {task_id:currentTaskId, action:'delete'};
+ handleSubmission('update_task.php', data);
});
+
function updateTaskList() {
$.post("list_tasks.php", function( data ) {
$( "#TaskList" ).html( data );
});
}
+
updateTaskList();