summaryrefslogtreecommitdiff
path: root/public/app/views/user
diff options
context:
space:
mode:
Diffstat (limited to 'public/app/views/user')
-rw-r--r--public/app/views/user/invitation.php164
1 files changed, 16 insertions, 148 deletions
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>