From a3dc1f0f55003ca2fb325ed2e3f974094f6cad2e Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Thu, 25 May 2023 09:30:37 +0300 Subject: break form scripts in parts; first pdf example --- core/classes/Benchmark.php | 15 +- core/classes/Cart.php | 4 +- core/classes/Registry.php | 17 +- core/classes/Route.php | 8 +- public/app/config/setup_application.php | 31 +-- public/app/controllers/Auth.php | 6 +- public/app/controllers/Office.php | 22 +- public/app/extends/App_user.php | 3 + public/app/views/js/attachments-handling.php | 171 +++++++++++++++ public/app/views/js/select2-supplementary.php | 101 +++++++++ public/app/views/js/submit/application-form.php | 54 +++++ public/app/views/js/submit/invitation-form.php | 52 +++++ public/app/views/templates/application.php | 266 ++++++++++-------------- public/app/views/user/invitation.php | 164 ++------------- 14 files changed, 558 insertions(+), 356 deletions(-) create mode 100644 public/app/views/js/attachments-handling.php create mode 100644 public/app/views/js/select2-supplementary.php create mode 100644 public/app/views/js/submit/application-form.php create mode 100644 public/app/views/js/submit/invitation-form.php 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 @@ '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 @@ + 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 @@ + \ 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 @@ + 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 @@ + \ 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 @@ -
+
@@ -31,185 +31,133 @@
+ + -

Synhmena

-
    -
  • uno
  • -
  • duo
  • -
  • tre
  • -
-
+
-
-
- - - - // track empty values + - - + - $('.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) - // }); - } - }); + + - }); - - + \ 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 @@ - -$(document).ready(function() { - // 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 { 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; - } - } + + + + -- cgit v1.2.3