diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index 0cc83d3c0..86b5d1e8b 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -42,6 +42,11 @@ class InfoCenter extends VileSci_Controller 'logtype' => 'Action', 'name' => 'Note added', 'message' => 'Note with title %s was added' + ), + 'updatenotiz' => array( + 'logtype' => 'Action', + 'name' => 'Note updated', + 'message' => 'Note with title %s was updated' ) ); private $uid; // contains the UID of the logged user @@ -381,6 +386,44 @@ class InfoCenter extends VileSci_Controller ->set_content_type('application/json') ->set_output(json_encode($result->retval)); } + + /** + * Updates a new Notiz for a person + * @param int $notiz_id + * @param int $person_id + * @return bool true if success + */ + public function updateNotiz($notiz_id, $person_id) + { + $titel = $this->input->post('notiztitel'); + $text = $this->input->post('notiz'); + + $result = $this->NotizModel->update( + $notiz_id, + array( + 'titel' => $titel, + 'text' => $text, + 'verfasser_uid' => $this->uid, + "updateamum" => 'NOW()', + "updatevon" => $this->uid + ) + ); + + + $json = FALSE; + + if (isSuccess($result)) + { + $json = TRUE; + + //set log "Notiz updated" + $this->_log($person_id, 'updatenotiz', array($titel)); + } + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($json)); + } /** * Loads Notizen view for a person, helper for reloading after ajax request diff --git a/application/views/system/infocenter/addNotiz.php b/application/views/system/infocenter/addNotiz.php index 8773b7cad..a8396fe40 100644 --- a/application/views/system/infocenter/addNotiz.php +++ b/application/views/system/infocenter/addNotiz.php @@ -1,4 +1,5 @@
+
@@ -19,6 +20,8 @@
+ +
diff --git a/application/views/system/infocenter/notizen.php b/application/views/system/infocenter/notizen.php index 23a0e6ef4..04b938086 100644 --- a/application/views/system/infocenter/notizen.php +++ b/application/views/system/infocenter/notizen.php @@ -1,19 +1,20 @@ - - - - - - - - - - - - - - - - - +
DatumNotizUser
insertamum), 'd.m.Y H:i:s') ?>titel) ?>verfasser_uid ?>
+ + + + + + + + + + + + + + + + +
DatumNotizUser
insertamum), 'd.m.Y H:i:s') ?>titel) ?>verfasser_uid ?>notiz_id ?>
\ No newline at end of file diff --git a/include/js/infocenter/infocenterDetails.js b/include/js/infocenter/infocenterDetails.js index 47812323d..0d409fe13 100644 --- a/include/js/infocenter/infocenterDetails.js +++ b/include/js/infocenter/infocenterDetails.js @@ -96,11 +96,45 @@ $(document).ready( $("#notizform").on("submit", function (e) { e.preventDefault(); - var personid = $("#hiddenpersonid").val(); + var personId = $("#hiddenpersonid").val(); + var notizId = $("#notizform :input[name='hiddenNotizId']").val(); var data = $(this).serializeArray(); - saveNotiz(personid, data); + + if (notizId !== '') + { + updateNotiz(notizId, personId, data); + } + else + { + saveNotiz(personId, data); + } } - ) + ); + + + //update notiz - autofill notizform + $(document).on("click", "#notiztable tbody tr", function () + { + var notizId = $(this).find("td:eq(3)").html(); + var notizTitle = $(this).find("td:eq(1)").text(); + var notizContent = this.title; + + $("#notizform label:first").text("Notiz ändern").css("color", "red"); + $("#notizform :input[type='reset']").css("display", "inline-block"); + + $("#notizform :input[name='hiddenNotizId']").val(notizId); + $("#notizform :input[name='notiztitel']").val(notizTitle); + $("#notizform :input[name='notiz']").val(notizContent); + } + ); + + //update notiz - abbrechen-button: reset styles + $("#notizform :input[type='reset']").click(function () + { + resetNotizFields(); + } + ); + }); // ----------------------------------------------------------------------------------------------------------------- @@ -220,6 +254,29 @@ function saveNotiz(personid, data) }); } +function updateNotiz(notizId, personId, data) +{ + $.ajax({ + type: "POST", + dataType: "json", + data: data, + url: "../updateNotiz/" + notizId + "/" + personId, + success: function (data, textStatus, jqXHR) + { + if (data) + { + refreshNotizen(); + refreshLog(); + resetNotizFields(); + } + }, + error: function (jqXHR, textStatus, errorThrown) + { + alert(textStatus + " - " + errorThrown + " - " + jqXHR.responseText); + } + }); +} + // ----------------------------------------------------------------------------------------------------------------- // methods executed after ajax (refreshers) @@ -252,7 +309,7 @@ function refreshNotizen() //readd tablesorter formatNotizTable() } - ); + ); } function formatNotizTable() @@ -261,3 +318,10 @@ function formatNotizTable() tablesortAddPager("notiztable", "notizpager", 10); $("#notiztable").addClass("table-condensed"); } + +function resetNotizFields() +{ + $("#notizform :input[name='hiddenNotizId']").val(""); + $("#notizform label:first").text("Notiz hinzufügen").css("color", "black"); + $("#notizform :input[type='reset']").css("display", "none"); +}