diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-25 09:30:37 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-25 09:30:37 +0300 |
| commit | a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e (patch) | |
| tree | 09aa5f8208460c5c2883209d7139d59ba2d623e3 /public/app/views/js | |
| parent | 2b1f4aed56c5bfbf014f3f871e9dcc336b5a31b7 (diff) | |
| download | gyraf1gov-a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e.tar.gz gyraf1gov-a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e.tar.bz2 gyraf1gov-a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e.zip | |
break form scripts in parts; first pdf example
Diffstat (limited to 'public/app/views/js')
| -rw-r--r-- | public/app/views/js/attachments-handling.php | 171 | ||||
| -rw-r--r-- | public/app/views/js/select2-supplementary.php | 101 | ||||
| -rw-r--r-- | public/app/views/js/submit/application-form.php | 54 | ||||
| -rw-r--r-- | public/app/views/js/submit/invitation-form.php | 52 |
4 files changed, 378 insertions, 0 deletions
diff --git a/public/app/views/js/attachments-handling.php b/public/app/views/js/attachments-handling.php new file mode 100644 index 0000000..4d97b0e --- /dev/null +++ b/public/app/views/js/attachments-handling.php @@ -0,0 +1,171 @@ +<script> +$(document).ready(function() { + + // Attachements handling + //////////////////////////////////////////////////////////////////////////// + + + // Modal HTML Creators + // ----------------------------------------------------------------------------- + + const modal_header = (title) => { + return [ + '<div class="modal-header">', + '<h4 class="modal-title" id="myModalLabel">', + title, + '</h4>', + '<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">', + '<span aria-hidden="true"></span>', + '</button>', + '</div>' + ].join('\n'); + } + + + const upload_file_form = () => { + return [ + '<form method="POST" id="file_upload_form" name="upload_file_form">', + + '<div class="modal-body">', + + '<input type="hidden" name="folder" value="'+ altID +'">', + + '<div class="form-group">', + '<label for="title">Τίτλος/Περιγραφή για το Αρχείο</label>', + '<input type="text" class="form-control " value="" name="title" id="title" placeholder="Τίτλος για το Αρχείο" required="">', + '</div>', + + '<div class="form-group">', + '<label class="control-label" for="file">Εισαγωγή Αρχείου</label>', + '<input class="form-control" type="file" id="file" name="file" required="">', + '</div>', + + '</div>', + + '<div class="modal-footer">', + '<div class="row" style="width: 50%;">', + '<div class="form-actions">', + '<div class="col col-4">', + '<buton type="button" class="btn btn-default js-modal-close col-12" data-bs-dismiss="modal">', + 'Κλείσιμο', + '</button>', + '</div>', + '<div class="col-8">', + '<button class="btn btn-success col-12" type="submit">Καταχώριση</button>', + '</div>', + '</div>', + '</div>', + '</div>', + + '</form>' + ].join('\n'); + } + + + const preview_article = (title, intro, body) => { + return [ + '<div class="modal-body">', + '<div class="post">', + + '<h2>'+ title +'</h2>', + + ((intro == '') ? '' : ('<div class="intro">'+ intro +'</div>')), + + '<div class="article-body">', + marked.parse(body, { sanitize: true }), + '</div>', + + '</div>', + '</div>', + '<div class="modal-footer">', + '<div class="row" style="width: 50%;">', + '<div class="form-actions">', + '<div class="col-md-4 col-md-offset-4 col-6 col-offset-3">', + '<buton type="button" class="btn btn-default js-modal-close col-12" data-bs-dismiss="modal">', + 'Κλείσιμο', + '</button>', + '</div>', + '</div>', + '</div>', + '</div>' + ].join('\n'); + } + + + /** When modal show-up + * ------------------------------------------------------------------------- + * ... prepare the manage-category form + * ... update select2 with possible parents + */ + $('#editorModal').on('show.bs.modal', event => { + let button = $(event.relatedTarget); // Button that triggered the modal + let action = button.data('action'); // action + // var modal = $(this); // modal object + + // update modal literature + + switch (action) { + case 'upload_file': + $("#editorModal .modal-content").html( + modal_header('Εισαγωγή Αρχείου') + upload_file_form() + ); + break; + + case 'preview': + let preview = preview_article( + $('.edit-post form input[name=title]').val(), + $('.edit-post form textarea[name=intro]').val(), + $('.edit-post form textarea[name=body]').val() + ); + $("#editorModal .modal-content").html( modal_header('Προεπισκόπηση') + preview); + break; + + default: + // do nothing + } + + }); + + + /** submit upload file event + * ------------------------------------------------------------------------- + */ + $('#editorModal').on('submit', 'form[name=upload_file_form]', function (event) { + event.preventDefault(); + + // create the FormData object + // --- -- -- - - - + var fd = new FormData(document.getElementById('file_upload_form')); + + // post the form (via ajax) + $.ajax({ + url: '/admin/api/file_upload', + type: 'POST', + data: fd, + contentType: false, + processData: false, + dataType: 'json', + success: function(response) { // on success + + if (response.success) { + files.push({ // ... update files array + id: response.id, + label: response.title, + path: response.path, + type: response.type + }); + draw_files_list(); + + $('#editorModal').modal('hide'); + + } else { + console.log('File not uploaded'); + } + } + }); + }); + + + +}); +</script> diff --git a/public/app/views/js/select2-supplementary.php b/public/app/views/js/select2-supplementary.php new file mode 100644 index 0000000..a7aa7e2 --- /dev/null +++ b/public/app/views/js/select2-supplementary.php @@ -0,0 +1,101 @@ +<script> + + // supplementary functions to select2 control + //////////////////////////////////////////////////////////////////////////// + + /** getValues + * --- -- -- - - - + * Get selected value(s) of Select2 control + * + * @param arg: source-element + * @return (string) value(s) comma-separated + */ + function getValues(srcElm) { + var res; + var obj = srcElm.select2('data'); // get delected data array + + if (obj.length === 0) return ''; // if empty list then nothig is selected + else { + var i = 0; + obj.forEach(function(elm){ // loop through object elements array + + if (i) res += ',' + elm.id; // if not first item, prepend ',' befor value(id) + else res = elm.id; // else set (first) checked value + + i++; + }); + } + return res; + } + + /** select2_set_text + * --- -- -- - - - + * select an (select2-)option by text + * onto a (single) select2 control + * + * @param control = jquery selector, + * @param t (string) = text of option + */ + function select2_set_text(control, t) { + opts = control.select2()[0].options; + var id; + for(i=0; i<opts.length; i++) { if (opts[i].text == t) id = i; } + control.val(id).trigger('change'); + } + + /** get_id_of_text + * --- -- -- - - - + * get id (=value) of an option with `t` as text + * onto a select2 control; + * + * Can be used on single or multiple select2 contols + * + * @param control = jquery selector, + * @param t (string) = text of option + */ + function get_id_of_text( control , t) { + opts = control.select2()[0].options; + var id = false; + for(i=0; i<opts.length; i++) { if (opts[i].text == t) id = i; } + return id; + } + + /** select2_set_multi_text + * --- -- -- - - - + * select several (select2-)options by text + * + * @param control = jquery selector, + * @param t_list (string) = list of selected texts + */ + function select2_set_multi_text(control, t_list) { /* define function */ + var ids = []; + t_list.forEach (t => { let id = get_id_of_text(control, t); + if (id !== false) ids.push(id); + }) + control.val(ids).change(); + } + + /** selected_text + * --- -- -- - - - + * get selected text of a select2 control + */ + function selected_text(control) { + if (typeof control.select2('data') === 'undefined') return false; + else if (control.select2('data').length == 0) return false; + else return control.select2('data')[0].text; + } + + /** + * get all selected texts from a multi-select2 contol + */ + function selected_multitexts(control) { + if (typeof control.select2('data') === 'undefined') return false; + else if (control.select2('data').length == 0) return false; + else { + var result = []; + control.select2('data').forEach( item => { result.push(item.text); }); + return result; + } + } + +</script>
\ No newline at end of file diff --git a/public/app/views/js/submit/application-form.php b/public/app/views/js/submit/application-form.php new file mode 100644 index 0000000..badff03 --- /dev/null +++ b/public/app/views/js/submit/application-form.php @@ -0,0 +1,54 @@ +<script> + $(document).ready(function() { + + // When form is submited + //////////////////////////////////////////////////////////////////////// + + $('.content-form form').submit( event => { + event.preventDefault(); + + if (false) { + alert('Τα δυο passrods δεν ταιριάζουν!'); + + } else { + + var data = { // select content data + of_article: selected_text($('select[name=of_article]')), + student_names: $('textarea[name=student_names]').val(), + of_department: $('input[name=of_department]').val(), + date: $('input[name=date]').val(), + time: $('input[name=time]').val(), + place: selected_text($('select[name=place]')), + rapporteur: selected_text($('select[name=rapporteur]')), + charge: $('textarea[name=charge]').val(), + apology: $('textarea[name=apology]').val(), + decision_reasoning: $('textarea[name=decision_reasoning]').val(), + decision: selected_text($('select[name=decision]')), + decision_more: $('input[name=decision_more]').val(), + president: selected_text($('select[name=president]')), + members: selected_multitexts($('select[name="members[]"]')) + }; + + var form_data = { // prepare data to post + subject: $('input[name=of_department]').val(), + content: JSON.stringify(data), + on_date: $('input[name=date]').val(), + user_id: $('input[name=id]').val() + } + + // select action url (add or update) + // var request = '/account/register'; + console.log(data); + + // send POST request + // $.post(request, form_data) + // .done(function( data ) { + // $('.classroom .content-form').html(data.message) + // }); + } + + }); + + + }); +</script> diff --git a/public/app/views/js/submit/invitation-form.php b/public/app/views/js/submit/invitation-form.php new file mode 100644 index 0000000..efeba27 --- /dev/null +++ b/public/app/views/js/submit/invitation-form.php @@ -0,0 +1,52 @@ +<script> + $(document).ready(function() { + + // When form is submited + //////////////////////////////////////////////////////////////////////////// + + $('form').submit( event => { + event.preventDefault(); + + if ($('input[name=password]').val() != $('input[name=confirm_password]').val()) { + alert('Τα δυο κωδικοί πρόσβασης δεν ταιριάζουν!'); + + } else if ($('input[name=password]').val() == "") { + alert('Ο κωδικός πρόσβασης δεν μπορεί να είναι κενός') + + } else if ( ($('input[name=password]').val() == '0') + || ($('input[name=password]').val() =='') ) { + alert('Παρκαλώ συμπληρώστε ένα τηλέφωνο επικοινωνίας') + + } else { + // prepare data to POST + var data = { + // identification fields + id: $('input[name=id]').val(), + invitation: $('input[name=invitation]').val(), + // data fields + first_name: $('input[name=first_name]').val(), + last_name: $('input[name=last_name]').val(), + father_name: $('input[name=father_name]').val(), + email: $('input[name=email]').val(), + registration_number: $('input[name=registration_number]').val(), + sector: $('select[name=sector]').select2('data')[0].text, + belonging_school: $('input[name=belonging_school]').val(), + position: $('select[name=position]').select2('data')[0].text, + phone: $('input[name=phone]').val(), + // access verification + password: $('input[name=password]').val() + }; + console.log(data); + + var request = '/account/activate'; // set action url + + // send POST request + $.post(request, data) + .done(function( data ) { + $('.office .content-form').html(`<h4>${data.title}<h4><br>${data.message}`) + }); + } + }); + + }); +</script>
\ No newline at end of file |
