| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- function add_case_template() {
- let url = '/manage/case-templates/add/modal' + case_param();
- $('#modal_case_template_json').load(url, function (response, status, xhr) {
- if (status !== "success") {
- ajax_notify_error(xhr, url);
- return false;
- }
- let editor = ace.edit("editor_detail",
- {
- autoScrollEditorIntoView: true,
- minLines: 30,
- });
- editor.setTheme("ace/theme/tomorrow");
- editor.session.setMode("ace/mode/json");
- editor.renderer.setShowGutter(true);
- editor.setOption("showLineNumbers", true);
- editor.setOption("showPrintMargin", false);
- editor.setOption("displayIndentGuides", true);
- editor.setOption("maxLines", "Infinity");
- editor.session.setUseWrapMode(true);
- editor.setOption("indentedSoftWrap", true);
- editor.renderer.setScrollMargin(8, 5)
- editor.setOptions({
- enableBasicAutocompletion: [{
- getCompletions: (editor, session, pos, prefix, callback) => {
- callback(null, [
- {value: 'name', score: 1, meta: 'name of the template'},
- {value: 'display', score: 1, meta: 'display name of the template'},
- {value: 'description', score: 1, meta: 'description of the template'},
- {value: 'author', score: 1, meta: 'author of the template'},
- {value: 'title_prefix', score: 1, meta: 'prefix of instantiated cases'},
- {value: 'summary', score: 1, meta: 'summary of the case'},
- {value: 'tags', score: 1, meta: 'tags of the case or the tasks'},
- {value: 'tasks', score: 1, meta: 'tasks of the case'},
- {value: 'note_groups', score: 1, meta: 'groups of notes'},
- {value: 'title', score: 1, meta: 'title of the task or the note group or the note'},
- {value: 'content', score: 1, meta: 'content of the note'},
- ]);
- },
- }],
- enableLiveAutocompletion: true,
- enableSnippets: true
- });
- $('#submit_new_case_template').on("click", function () {
- let data_sent = Object();
- data_sent['case_template_json'] = editor.getSession().getValue();
- data_sent['csrf_token'] = $("#csrf_token").val();
- post_request_api('/manage/case-templates/add', JSON.stringify(data_sent), false, function() {
- window.swal({
- title: "Adding...",
- text: "Please wait",
- icon: "/static/assets/img/loader.gif",
- button: false,
- allowOutsideClick: false
- });
- })
- .done((data) => {
- if (notify_auto_api(data)) {
- refresh_case_template_table();
- $('#modal_case_template').modal('hide');
- }
- })
- .fail((error) => {
- let data = error.responseJSON;
- $('#submit_new_case_template').text('Save');
- $('#alert_case_template_edit').text(data.message);
- if (data.data && data.data.length > 0) {
- let output='<li>'+ sanitizeHTML(data.data) +'</li>';
- $('#case_template_err_details_list').append(output);
- $('#alert_case_template_details').show();
- }
- $('#alert_case_template_edit').show();
- })
- .always((data) => {
- window.swal.close();
- });
- return false;
- })
- });
- $('#modal_case_template').modal({ show: true });
- }
- $('#case_templates_table').dataTable( {
- "ajax": {
- "url": `/manage/case-templates/list${case_param()}`,
- "contentType": "application/json",
- "type": "GET",
- "data": function ( d ) {
- if (d.status == 'success') {
- return JSON.stringify( d.data );
- } else {
- return JSON.stringify([]);
- }
- }
- },
- "order": [[ 0, "desc" ]],
- "autoWidth": false,
- "columns": [
- {
- "data": "id",
- "render": function ( data, type, row ) {
- return '<a href="#" onclick="case_template_detail(\'' + row['id'] + '\');">' + sanitizeHTML(data) +'</a>';
- }
- },
- {
- "data": "display_name",
- "render": function ( data, type, row ) {
- return '<a href="#" onclick="case_template_detail(\'' + row['id'] + '\');">' + sanitizeHTML(data) +'</a>';
- }
- },
- {
- "data": "description"
- },
- {
- "data": "added_by"
- },
- {
- "data": "created_at"
- },
- {
- "data": "updated_at"
- }
- ]
- }
- );
- function refresh_case_template_table() {
- $('#case_templates_table').DataTable().ajax.reload();
- notify_success("Refreshed");
- }
- function delete_case_template(id) {
- swal({
- title: "Are you sure ?",
- text: "You won't be able to revert this !",
- icon: "warning",
- buttons: true,
- dangerMode: true,
- confirmButtonColor: '#3085d6',
- cancelButtonColor: '#d33',
- confirmButtonText: 'Yes, delete it!'
- })
- .then((willDelete) => {
- if (willDelete) {
- post_request_api(`/manage/case-templates/delete/${id}`)
- .done((data) => {
- if(notify_auto_api(data)) {
- window.location.href = '/manage/case-templates' + case_param();
- }
- });
- } else {
- swal("Pfew, that was close");
- }
- });
- }
- function case_template_detail(ctempl_id) {
- let url = '/manage/case-templates/' + ctempl_id + '/modal' + case_param();
- $('#modal_case_template_json').load(url, function (response, status, xhr) {
- if (status !== "success") {
- ajax_notify_error(xhr, url);
- return false;
- }
- let editor = ace.edit("editor_detail",
- {
- autoScrollEditorIntoView: true,
- minLines: 30,
- });
- editor.setTheme("ace/theme/tomorrow");
- editor.session.setMode("ace/mode/json");
- editor.renderer.setShowGutter(true);
- editor.setOption("showLineNumbers", true);
- editor.setOption("showPrintMargin", false);
- editor.setOption("displayIndentGuides", true);
- editor.setOption("maxLines", "Infinity");
- editor.session.setUseWrapMode(true);
- editor.setOption("indentedSoftWrap", true);
- editor.renderer.setScrollMargin(8, 5)
- editor.setOptions({
- enableBasicAutocompletion: [{
- getCompletions: (editor, session, pos, prefix, callback) => {
- callback(null, [
- {value: 'name', score: 1, meta: 'name of the template'},
- {value: 'display_name', score: 1, meta: 'display name of the template'},
- {value: 'description', score: 1, meta: 'description of the template'},
- {value: 'author', score: 1, meta: 'author of the template'},
- {value: 'title_prefix', score: 1, meta: 'prefix of instantiated cases'},
- {value: 'summary', score: 1, meta: 'summary of the case'},
- {value: 'tags', score: 1, meta: 'tags of the case or the tasks'},
- {value: 'tasks', score: 1, meta: 'tasks of the case'},
- {value: 'note_groups', score: 1, meta: 'groups of notes'},
- {value: 'title', score: 1, meta: 'title of the task or the note group or the note'},
- {value: 'content', score: 1, meta: 'content of the note'},
- ]);
- },
- }],
- enableLiveAutocompletion: true,
- enableSnippets: true
- });
- $('#submit_new_case_template').on("click", function () {
- update_case_template(ctempl_id, editor, false, false);
- });
- $('#submit_delete_case_template').on("click", function () {
- delete_case_template(ctempl_id);
- });
- });
- $('#modal_case_template').modal({ show: true });
- }
- function update_case_template(ctempl_id, editor, partial, complete){
- event.preventDefault();
- let data_sent = Object();
- data_sent['case_template_json'] = editor.getSession().getValue();
- data_sent['csrf_token'] = $("#csrf_token").val();
- $('#alert_case_template_edit').empty();
- $('#alert_case_template_details').hide();
- $('#case_template_err_details_list').empty();
- post_request_api(`/manage/case-templates/update/${ctempl_id}`, JSON.stringify(data_sent), false, function() {
- window.swal({
- title: "Updating...",
- text: "Please wait",
- icon: "/static/assets/img/loader.gif",
- button: false,
- allowOutsideClick: false
- });
- })
- .done((data) => {
- notify_auto_api(data);
- })
- .fail((error) => {
- let data = error.responseJSON;
- $('#submit_new_case_template').text('Update');
- $('#alert_case_template_edit').text(data.message);
- if (data.data && data.data.length > 0) {
- let output='<li>'+ sanitizeHTML(data.data) +'</li>';
- $('#case_template_err_details_list').append(output);
- $('#alert_case_template_details').show();
- }
- $('#alert_case_template_edit').show();
- })
- .always((data) => {
- window.swal.close();
- });
- return false;
- }
- function fire_upload_case_template() {
- let url = '/manage/case-templates/upload/modal' + case_param();
- $('#modal_upload_case_template_json').load(url, function (response, status, xhr) {
- if (status !== "success") {
- ajax_notify_error(xhr, url);
- return false;
- }
- });
- $('#modal_upload_case_template').modal({ show: true });
- }
- function upload_case_template() {
- if ($("#input_upload_case_template").val() !== "")
- {
- var file = $("#input_upload_case_template").get(0).files[0];
- var reader = new FileReader();
- reader.onload = function (e) {
- fileData = e.target.result
- var data = new Object();
- data['csrf_token'] = $('#csrf_token').val();
- data['case_template_json'] = fileData;
- post_request_api('/manage/case-templates/add', JSON.stringify(data), false, function() {
- window.swal({
- title: "Adding...",
- text: "Please wait",
- icon: "/static/assets/img/loader.gif",
- button: false,
- allowOutsideClick: false
- });
- })
- .done((data) => {
- notify_auto_api(data);
- jsdata = data;
- if (jsdata.status == "success") {
- refresh_case_template_table();
- $('#modal_upload_case_template').modal('hide');
- }
- })
- .fail((error) => {
- let data = error.responseJSON;
- $('#alert_upload_case_template').text(data.message);
- if (data.data && data.data.length > 0) {
- let output='<li>'+ sanitizeHTML(data.data) +'</li>';
- $('#upload_case_template_err_details_list').append(output);
- $('#alert_upload_case_template_details').show();
- }
- $('#alert_upload_case_template').show();
- })
- .always((data) => {
- $("#input_upload_case_template").val("");
- window.swal.close();
- });
- };
- reader.readAsText(file);
- }
- return false;
- }
- function downloadCaseTemplateDefinition() {
- event.preventDefault();
- let editor = ace.edit("editor_detail");
- let data = editor.getSession().getValue();
- let filename = "case_template.json";
- download_file(filename, 'text/json' , data);
- }
|