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 | |
| parent | 2b1f4aed56c5bfbf014f3f871e9dcc336b5a31b7 (diff) | |
| download | gyraf1gov-a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e.tar.gz gyraf1gov-a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e.tar.bz2 gyraf1gov-a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e.zip | |
break form scripts in parts; first pdf example
| -rw-r--r-- | core/classes/Benchmark.php | 15 | ||||
| -rw-r--r-- | core/classes/Cart.php | 4 | ||||
| -rw-r--r-- | core/classes/Registry.php | 17 | ||||
| -rw-r--r-- | core/classes/Route.php | 8 | ||||
| -rw-r--r-- | public/app/config/setup_application.php | 31 | ||||
| -rw-r--r-- | public/app/controllers/Auth.php | 6 | ||||
| -rw-r--r-- | public/app/controllers/Office.php | 22 | ||||
| -rw-r--r-- | public/app/extends/App_user.php | 3 | ||||
| -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 | ||||
| -rw-r--r-- | public/app/views/templates/application.php | 266 | ||||
| -rw-r--r-- | public/app/views/user/invitation.php | 164 |
14 files changed, 558 insertions, 356 deletions
diff --git a/core/classes/Benchmark.php b/core/classes/Benchmark.php index 8aa040d..a8b4145 100644 --- a/core/classes/Benchmark.php +++ b/core/classes/Benchmark.php @@ -52,7 +52,8 @@ class Benchmark { /** add_timespot * --- * add new timespot - * @param $key : label of timespot + * + * @param string $key : label of timespot */ public static function add_spot(string $key) { @@ -62,7 +63,10 @@ class Benchmark { /** exist + * --- * checks if a benchmark spot with label $key exists + * + * @param string $key : label of timespot */ public static function exist(string $key) : bool { @@ -71,7 +75,8 @@ class Benchmark { /** desableReport - * (Self-explanatory) + * --- + * desables report exporting */ public static function disableReport() { @@ -84,7 +89,7 @@ class Benchmark { * renders performance report * as html comment at the end of webpage in various modes * - * @param $mode (int): report format id + * @param int $mode: report format id * ... default: BENCH_REPORT_COMMENT (5) = report as html comment; * ... for more report-formats check the BENCH_REPORT_* defines */ @@ -198,9 +203,9 @@ class Benchmark { $output .= $suffix; - } - return $output; + } else { return; } + return $output; } } diff --git a/core/classes/Cart.php b/core/classes/Cart.php index 4e6f585..f90eab6 100644 --- a/core/classes/Cart.php +++ b/core/classes/Cart.php @@ -1,5 +1,7 @@ <?php - +/** TODO: + * not implemented yet + */ class Cart { diff --git a/core/classes/Registry.php b/core/classes/Registry.php index 119e2b9..02a1ec5 100644 --- a/core/classes/Registry.php +++ b/core/classes/Registry.php @@ -24,7 +24,7 @@ class Registry * ------------------------------------------------------------------------- */ - /** @var $records (array) + /** @var array $records * keeps all ready-to-use records * --- --- -- - - - * @@ -37,7 +37,7 @@ class Registry */ private static $records = Array(); - /** @var $wish (array) + /** @var array $wish * keeps all records that will be carried-out later (if ever) * --- -- -- - - - * @@ -54,8 +54,8 @@ class Registry * --- -- -- - - - * store $data to the registry undel the label $key * - * @param $key (string) - * @param $data * + * @param string $key + * @param mixed $data */ static function set($key, $data) { @@ -80,8 +80,8 @@ class Registry * get data from registry, * stored under the label $key * - * @param $key (string): the label - * @return data (mixed) + * @param string $key : the label + * @return mixed data */ static function get($key) { @@ -107,7 +107,7 @@ class Registry * that a 'vow' will not use system resources to prepare * the data/object/handler/etc until/if-ever is called. * - * @param $label (string): label / refference key + * @param string $label : label / refference key * @param function : */ static function vow($label, $function) @@ -120,6 +120,9 @@ class Registry * --- * this is the method that carries out * the promissed function (with arguments) + * + * @param string $label + * @param array $args */ static function use($label, $args=[]) { diff --git a/core/classes/Route.php b/core/classes/Route.php index 072723c..ab0a0a7 100644 --- a/core/classes/Route.php +++ b/core/classes/Route.php @@ -20,9 +20,9 @@ class Route { /** add (route) * --- - * @param $expression : (string) static or regex matcher - * @param $function : callback function to be executed if expression is matched - * @param $method : get / post / any + * @param string $expression : static or regex matcher + * @param callback $function : function to be executed if expression is matched + * @param string $method : get / post / any */ public static function add( $expression, $function, $method = 'get' ) { @@ -36,7 +36,7 @@ class Route { /** notFound($function) * --- - * @param $function : call back function to be executed + * @param callback $function : callback function to be executed */ public static function notFound($function) { diff --git a/public/app/config/setup_application.php b/public/app/config/setup_application.php index d44f59d..a5b7557 100644 --- a/public/app/config/setup_application.php +++ b/public/app/config/setup_application.php @@ -169,7 +169,7 @@ define('TEACHER_SECTORS', [ /** GENDER-ed constant arrays (LGBTQIA+ inclusive) - * they use pronounces as key instead of binary gender-flag + * they use pronounces as key instead of a binary gender-flag * ----------------------------------------------------------------------------- */ @@ -218,48 +218,41 @@ define('REGISTRATION_FORM', [ [ 'name' => 'first_name', 'label' => 'Όνομα', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'last_name', 'label' => 'Επίθετο', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'email', 'label' => 'Email', 'type' => 'email', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'father_name', 'label' => 'Πατρώνυμο', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'registration_number', 'label' => 'Αριθμός μητρώου', 'class' => 'col-8', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'sector', 'label' => 'Κλάδος / Ειδικότητα', - 'value' => 'auto', 'type' => 'select', - 'attributes' => ['required'], + 'attributes' => ['required', 'auto'], 'options' => TEACHER_SECTORS ], [ 'name' => 'belonging_school', 'label' => 'Σχολείο τοποθέτησης', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], // [ // working school = (obviously) is the current school // 'name' => 'working_school', @@ -270,16 +263,14 @@ define('REGISTRATION_FORM', [ 'name' => 'position', 'label' => 'Θέση', 'type' => 'select', - 'value' => 'auto', - 'attributes' => ['required'], + 'attributes' => ['required', 'auto'], 'options' => [] ], [ 'name' => 'phone', 'label' => 'Τηλέφωνο', 'class' => 'col-8', - 'value' => 'auto', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'password', @@ -340,7 +331,7 @@ define('APPLICATION_FORM', [ 'name' => 'phone', 'label' => 'Τηλέφωνο', 'class' => 'col-5', - 'attributes' => ['required'] + 'attributes' => ['required', 'auto'] ], [ 'name' => 'email', diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index d52b6c9..e2fe989 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -50,6 +50,7 @@ class Auth { ->set('first_name', $record['first_name']) ->set('last_name', $record['last_name']) ->set('father_name', $record['father_name']) + ->set('phone', $record['phone']) ->set('email', $record['email']) ->set('sector', $record['sector']) ->set('position', $record['position']) @@ -172,7 +173,7 @@ class Auth { $form_setup->form[$key]->options = $gendered_position; // attach default values - $form_setup->defaults->values = $user; + $form_setup->defaults = $user; // get Form's HTML and Jsvascript $form = JsonToForm::json_form($form_setup, [ @@ -180,7 +181,7 @@ class Auth { ['name' => 'id', 'value' => $user->id], ['name' => 'invitation', 'value' => $user->invitation] - ]); + ]); // print_r($form_setup); die(); Render::view('user/invitation', [ 'form' => $form, @@ -231,6 +232,7 @@ class Auth { 'first_name' => $user->get('first_name'), 'last_name' => $user->get('last_name'), 'father_name' => $user->get('father_name'), + 'phone' => $user->get('phone'), 'email' => $user->get('email'), 'sector' => $user->get('sector'), 'position' => $user->get('position'), diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php index 5038200..d4b0217 100644 --- a/public/app/controllers/Office.php +++ b/public/app/controllers/Office.php @@ -118,12 +118,12 @@ class Office { - /** (any) petition + /** request any (empty/new) petition form * - * check if user is authorized to view the content; - * if so, prepare and render the petition view + * The method acts as an authorization checker and internal router + * to actual petition form-templates * - * @param $petition_type (string): [common|penalty] + * @param $petition_tag (string): petition type ex. [common|penalty] */ public static function request_petition($petition_tag) { @@ -135,8 +135,9 @@ class Office { 'moto' => 'Forbidden', 'message' => 'Για να έχετε πρόσβαση, θα πρέπει πρώτα να συνδεθείτε' ]); - die(); // then end; - } + die(); // then die(); + + } // else continue... $token = $manager->getUserToken(); // from token $user = $token->getUser(); // create user @@ -160,8 +161,9 @@ class Office { } - /** render application form + /** render an (empty/new) application form * + * @param array $opts : user identity ([user_id => id]) */ private static function render_application_form($opts) { @@ -192,8 +194,6 @@ class Office { ? GENDERED_POSITIONS['she'] : GENDERED_POSITIONS['he']; - - // #4: get Form's HTML and Javascript ---------------------------------- $form = JsonToForm::json_form($form_setup, [ ['name' => 'user_id', 'value' => $user_id] // pass user identity @@ -204,8 +204,10 @@ class Office { } - /** render penalty form + /** + * render an (empty/new) penalty form * + * @param array $opts : user identity ([user_id => id]) */ private static function render_penalty_form($opts) { diff --git a/public/app/extends/App_user.php b/public/app/extends/App_user.php index bb3d61d..dd41e2c 100644 --- a/public/app/extends/App_user.php +++ b/public/app/extends/App_user.php @@ -40,6 +40,7 @@ class App_user extends User private $last_name; private $father_name; private $registration_number; + private $phone; private $email; private $sector; private $belonging_school; @@ -144,6 +145,7 @@ class App_user extends User case 'first_name': $this->first_name = $val; return $this; break; case 'last_name': $this->last_name = $val; return $this; break; case 'father_name': $this->father_name = $val; return $this; break; + case 'phone': $this->phone = $val; return $this; break; case 'email': $this->email = $val; return $this; break; case 'sector': $this->sector = $val; return $this; break; case 'position': $this->position = $val; return $this; break; @@ -171,6 +173,7 @@ class App_user extends User case 'first_name': return $this->first_name; break; case 'last_name': return $this->last_name; break; case 'father_name': return $this->father_name; break; + case 'phone': return $this->phone; break; case 'email': return $this->email; break; case 'sector': return $this->sector; break; case 'position': return $this->position; break; 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 diff --git a/public/app/views/templates/application.php b/public/app/views/templates/application.php index a6b2b6b..f1f45fb 100644 --- a/public/app/views/templates/application.php +++ b/public/app/views/templates/application.php @@ -12,7 +12,7 @@ </head> <body class="office central-form"> -<div class='container'> + <div class='container'> <div class="content max720px"> <div class='content-form'> @@ -31,185 +31,133 @@ </form> </div> + <!-- attachments --> + <?php /* exclude until beta version <div class="info"> - <h4>Synhmena</h4> - <ul> - <li>uno</li> - <li>duo</li> - <li>tre</li> - </ul> - </div> + <div class="row form-group"> - </div> - </div> - -</body> -<script> -var values = {}; -var empty = ''; + <label class="control-label col-sm-12" for="media">Συνημμένα</label> -$(document).ready(function() { + <div class="col-sm-12 post-media"> - // supplementary functions to select2 control - //////////////////////////////////////////////////////////////////////////// + <!-- Button trigger modal --> + <button type="button" class="btn btn-sm btn-success pull-right over-bar" + data-bs-toggle="modal" data-bs-target="#editorModal" data-action="upload_file"> + <i class="fas fa-plus"></i> Προσθήκη + </button> - /** 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; - } + <ul id="files_list"> + </ul> - /** 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'); - } + </div> - /** 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(); - } + </div> + </div> + */ + ?> + </div> + </div> - /** - * 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; - } + <!-- MODAL for file uploads and preview --> + <div class="modal fade" id="editorModal" aria-labelledby="myModalLabel" aria-hidden="true"> + <div class="modal-dialog modal-lg" role="document"> + <div class="modal-content"> + <!-- content will be dynamic --> + </div> + </div> + </div> - /** - * 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; - } - } +</body> - // intializations from form-definition - //////////////////////////////////////////////////////////////////////////// +<!-- SCRIPTS +//////////////////////////////////////////////////////////////////////////////// +--> - <?=$form['init_js']?> +<script>// initialize needed global variables + var values = {}; + var empty = ''; +</script> - // track empty values +<?php // include select2 supplementary functions //////////////////////////////////////////////////////////////////////////// + Render::view('js/select2-supplementary'); +?> - - +<script>// pass dynamic js prepared by form designer + $(document).ready(function() { - // When form is submited - //////////////////////////////////////////////////////////////////////////// + // intializations from form-definition + //////////////////////////////////////////////////////////////////////// + <?=$form['init_js']?> + + }); +</script> - $('.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); +<?php // handle form submition + //////////////////////////////////////////////////////////////////////////// + Render::view('js/submit/application-form'); +?> - // send POST request - // $.post(request, form_data) - // .done(function( data ) { - // $('.classroom .content-form').html(data.message) - // }); - } - }); +<?php // include attachments handling + //////////////////////////////////////////////////////////////////////////// + Render::view('js/attachments-handling'); +?> +</html> - }); -</script> -</html> +<!-- application pdf template + check: http://pdfmake.org/playground.html + // playground requires you to assign document definition to a variable called dd + + var dd = { + content: [ + 'APPLICATION:\n\n', + { + alignment: 'justify', + columns: [ + { + text: [ + 'NAME: My Name', + 'Father: I do', + 'Mother:Me too', + 'Specs: Some quite big Address Lorem ipsum dolor sit amet, consectetur adipisicing elit' + ].join('\n\n') + }, + { + text:[ + 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', + 'Malit profecta versatur nomine ocurreret multavit, officiis viveremus aeternum.', + 'Quando nostros congressus susceperant concederetur leguntur iam, vigiliae democritea tantopere causae.', + 'Atilii plerumque ipsas potitur pertineant multis rem quaeri pro, legendum didicisse credere ex maluisset per videtis.', + 'Cur discordans praetereat aliae ruinae dirigentur orestem eodem, praetermittenda divinum.', + 'Collegisti, deteriora malint loquuntur officii cotidie finitas referri doleamus ambigua acute.', + 'Adhaesiones ratione beate arbitraretur detractis perdiscere, constituant hostis polyaeno.', + 'Diu concederetur.' + ].join('\n') + } + ] + }, + '\n\nOh, don\'t forget, we can use everything from styling examples (named styles, custom overrides) here as well.', + '\n\nWow, you\'ve read the whole document! Congratulations :D' + ], + styles: { + header: { + fontSize: 18, + bold: true + }, + bigger: { + fontSize: 15, + italics: true + } + }, + defaultStyle: { + columnGap: 20 + } + + } +-->
\ No newline at end of file diff --git a/public/app/views/user/invitation.php b/public/app/views/user/invitation.php index 34cfbf6..030c1d3 100644 --- a/public/app/views/user/invitation.php +++ b/public/app/views/user/invitation.php @@ -59,108 +59,19 @@ </body> -<script> -var values = {}; -var empty = ''; +<script>// initialize needed global variables + var values = {}; + var empty = ''; +</script> -$(document).ready(function() { - // supplementary functions to select2 control +<?php // include select2 supplementary functions //////////////////////////////////////////////////////////////////////////// + Render::view('js/select2-supplementary'); +?> - /** 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(); - } - - - /** - * get selected text of a select2 control - */ - function selected_text(control) { - if (control.select2('data').lenght == 0) return false - else return control.select2('data')[0].text; - } - - /** - * get all selected texts from a multi-select2 contol - */ - function selected_multitexts(control) { - if (control.select2('data').legth == 0) return false; - else { - var result = []; - control.select2('data').forEach( item => { result.push(item.text); }); - return result; - } - } +<script> +$(document).ready(function() { // intializations from form-definition //////////////////////////////////////////////////////////////////////////// @@ -168,60 +79,17 @@ $(document).ready(function() { <?=$form['init_js']?> - // track empty values + // set known values //////////////////////////////////////////////////////////////////////////// <?=$form['values_js']?> - - // 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> + + +<?php // handle form submition + //////////////////////////////////////////////////////////////////////////// + Render::view('js/submit/invitation-form'); +?> </html> |
