diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-06-12 21:59:00 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-06-12 21:59:00 +0300 |
| commit | 453c2d1183e9fcfe262a03e22365de5c76abd877 (patch) | |
| tree | 8196eef11340faaa2d78c64626e0f57a8d1e9e3d | |
| parent | 7f37ac9bc171ff3609e49f46466d1cd778e234c1 (diff) | |
| download | gyraf1gov-453c2d1183e9fcfe262a03e22365de5c76abd877.tar.gz gyraf1gov-453c2d1183e9fcfe262a03e22365de5c76abd877.tar.bz2 gyraf1gov-453c2d1183e9fcfe262a03e22365de5c76abd877.zip | |
set viewport meta for mobile devices
| -rw-r--r-- | public/.htaccess | 65 | ||||
| -rw-r--r-- | public/app/controllers/JsonToForm.php | 265 | ||||
| -rw-r--r-- | public/app/views/components/header_includes.php | 6 | ||||
| -rw-r--r-- | public/app/views/error/404.php | 1 | ||||
| -rw-r--r-- | public/app/views/error/general.php | 1 | ||||
| -rw-r--r-- | public/app/views/group.php | 13 | ||||
| -rw-r--r-- | public/app/views/item.php | 4 | ||||
| -rw-r--r-- | public/app/views/templates/admin_petitions.php | 3 | ||||
| -rw-r--r-- | public/app/views/templates/admin_users.php | 3 | ||||
| -rw-r--r-- | public/app/views/templates/application.php | 1 | ||||
| -rw-r--r-- | public/app/views/templates/create_pdf.php | 1 | ||||
| -rw-r--r-- | public/app/views/templates/invite.php | 5 | ||||
| -rw-r--r-- | public/app/views/templates/penalty.php | 1 | ||||
| -rw-r--r-- | public/app/views/user/control.php | 1 | ||||
| -rw-r--r-- | public/app/views/user/invitation.php | 1 | ||||
| -rw-r--r-- | public/app/views/user/login.php | 5 | ||||
| -rw-r--r-- | public/app/views/user/panel.php | 3 | ||||
| -rw-r--r-- | public/app/views/user/update_password.php | 5 | ||||
| -rw-r--r-- | public/app/views/user/update_properties.php | 5 | ||||
| -rw-r--r-- | public/app/views/welcome.php | 280 |
20 files changed, 39 insertions, 630 deletions
diff --git a/public/.htaccess b/public/.htaccess index fbc5167..d4d7c3d 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,59 +1,6 @@ ## Introduce the Server Header add Origin-Name coder -<IfModule mod_mime.c> - - # # Data interchange - # - # # 2.2.x+ - # AddType text/xml xml - # # 2.2.x - 2.4.x - # AddType application/json json - # AddType application/rss+xml rss - # # 2.4.x+ - # AddType application/json map - # - # # JavaScript - # # 2.2.x+ - # # See: https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages. - AddType apprication/javascript js mjs - - # # Manifest files - # # 2.2.x+ - # AddType application/manifest+json webmanifest - # AddType text/cache-manifest appcache - # - # # Media files - # # 2.2.x - 2.4.x - # AddType audio/mp4 f4a f4b m4a - # AddType audio/ogg oga ogg spx - # AddType video/mp4 mp4 mp4v mpg4 - # AddType video/ogg ogv - # AddType video/webm webm - # AddType video/x-flv flv - # # 2.2.x+ - # AddType image/svg+xml svgz - # AddType image/x-icon cur - # # 2.4.x+ - AddType image/webp webp - - # # Web fonts - # # 2.2.x - 2.4.x - # AddType application/vnd.ms-fontobject eot - # # 2.2.x+ - AddType font/woff woff - AddType font/woff2 woff2 - AddType font/ttf ttf - AddType font/collection ttc - AddType font/otf otf - - # # Other - # # 2.2.x+ - # AddType text/vtt vtt - -</IfModule> - - ### Deny access to specific folders ## deny all files too @@ -117,14 +64,14 @@ AddOutputFilterByType DEFLATE application/json ### ### CACHE-CONTROL HEADERS # CACHE-CONTROL IMAGES 100days -### <filesMatch ".(jpg|jpeg|png|webp|gif|ico)$"> -### Header set Cache-Control "max-age=8640000, public" -### </filesMatch> +<filesMatch ".+\.(jpg|jpeg|png|webp|gif|ico)$"> + Header set Cache-Control "max-age=8640000, public" +</filesMatch> # CACHE-CONTROL FONTS 200days -### <filesMatch ".(ttf|woff|woff2)$"> -### Header set Cache-Control "max-age=17280000, public" -### </filesMatch> +<filesMatch "/+\.(ttf|woff|woff2)$"> + Header set Cache-Control "max-age=17280000, public" +</filesMatch> # CACHE-CONTROL CSS and JS 30days ### <filesMatch ".(css|js)$"> diff --git a/public/app/controllers/JsonToForm.php b/public/app/controllers/JsonToForm.php index 5e16472..db8af11 100644 --- a/public/app/controllers/JsonToForm.php +++ b/public/app/controllers/JsonToForm.php @@ -417,268 +417,3 @@ class JsonToForm $ref2Select2JS = ""; // references to Select2-controls Javascript $initSelectsJS = ""; // js to initialize select fields (single or multiple) */ - - - /** post-DOM-end + scripts - * - * </form> - * </div> - * <!-- DOM ENDS HERE --> - * - * <!-- scripts and libraries - * load and register one by one, so you don't need to worry about if they are ready --> - * <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> - * <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/1.4.1/jquery-migrate.min.js"></script> - * <script src="/js/bootstrap.min.js"></script> - * <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.full.min.js"></script> - * <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/i18n/el.js"></script> - * <script> - * // NOW RUN EVERYTHING AFTER JQUERY (AND DOM ready) - * // ----------------------------------------------------------------------------- - * //////////////////////////////////////////////////////////////////////////////// - * - * // 00. FLAGS and NEEDED FUNCTIONS - * // --------------------------------------------------------------------------- - * ////////////////////////////////////////////////////////////////////////////// - * - * var waitingResponse = false; // flag for an ajax request that was sent and still waiting response - * - * // pure JS ajax GET request - * // return data as JSON - * // no fancy things like UTF8; if needed use base64 --------------------------- - * function ajax_get(url, callback) { - * var xmlhttp = new XMLHttpRequest(); - * xmlhttp.onreadystatechange = function() { - * if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - * - * try { - * var data = JSON.parse(xmlhttp.responseText); - * } catch(err) { - * console.log(err.message + ' in ' + xmlhttp.responseText); - * return; - * } - * callback(data); - * } - * }; - * - * xmlhttp.open("GET", url, true); - * xmlhttp.send(); - * } - * - * - * // 01. MENU MANAGEMENT - * // --------------------------------------------------------------------------- - * ////////////////////////////////////////////////////////////////////////////// - * - * // menu management - * // --------------------------------------------------------------------------- - * $('.dropdown-item').on('click', function(e){ - * e.preventDefault(); - * - * if (!waitingResponse) { - * waitingResponse = true; - * - * var r = confirm('Δεν έχετε αποθηκεύσει το αντικείμενο!\nΘέλετε σίγουρα να εγκαταλείψετε τη σελίδα;'); - * if (r == true) { - * - * // all data-goto have the format: 'method,uri_address' - * // uri_address is the url to call - * // method options: - * // * url : means goto url (redirect) - * // * ajax : means call url via ajax; if 'success = true' then goto '/' after that - * // ----------------------------------------------------------------------- - * var opt = $(this).data('goto').split(','); // split data-goto - * - * if (opt[0] == 'url') { // if method = url - * window.location.href = opt[1]; - * } - * else { // else, method = ajax - * ajax_get(opt[1], function(response) { - * if (response.success) { - * window.location.href = '/'; - * } - * }); - * } - * - * } - * else { - * // user did not confirmed the selection; do nothing - * } - * - * waitingResponse = false; - * } - * - * }); - * - * // 02. USER INTERFACE - * // --------------------------------------------------------------------------- - * ////////////////////////////////////////////////////////////////////////////// - * - * // tabs to accorderon -------------------------------------------------------- - * ////////////////////////////////////////////////////////////////////////////// - * - * // FUNCTION: Set tabsContainer height - * // acording to which tab is visible - * // and tab mode (tabs|acordeon) - * // --------------------------------------------------------------------------- - * function set_tabsContainer_height() { - * var ch_; // content height - * var tc_base; // tabs-container base height - * tc_base = ($(window).width() > 650) ? 100 : 400; - * if ($('#content1').is(':visible')) ch_ = $('#content1').height(); - * if ($('#content2').is(':visible')) ch_ = $('#content2').height(); - * if ($('#content3').is(':visible')) ch_ = $('#content3').height(); - * if ($('#content4').is(':visible')) ch_ = $('#content4').height(); - * if ($('#content5').is(':visible')) ch_ = $('#content5').height(); - * if ($('#content6').is(':visible')) ch_ = $('#content6').height(); - * - * $('#tabsContainer').height(ch_ + tc_base); - * - * } - * set_tabsContainer_height(); // init (run for 1st time) - * - * // on tab selection - * // calculate tabsContainer height - * $('input:radio[name="tabs"]').change( function(){ - * set_tabsContainer_height() - * }); - * - * // on window change - * // set tabsContainer height - * $( window ).resize(function() { - * set_tabsContainer_height(); - * }); - * - * - * - * // 03. form-control form-control-smS - * // --------------------------------------------------------------------------- - * ////////////////////////////////////////////////////////////////////////////// - * - * // Select2 controls - * ////////////////////////////////////////////////////////////////////////////// - * - * // FUNCTION: Get selected value(s) of Select2 control - * // pass arg: source-element - * // return: 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; - * } - * - * // patch select2-multiple widths - * // --------------------------------------------------------------------------- - * $('.select-field').select2({ width: '100%' }); - * - * // init select2 fields - * // (embed from php) - * // --------------------------------------------------------------------------- - * <?=$initSelectsJS?> - * - * - * // 04. FORM-LOGIC - * // --------------------------------------------------------------------------- - * ////////////////////////////////////////////////////////////////////////////// - * - * // FUNCTION: Report empty fields - * // --------------------------------------------------------------------------- - * function reportEmpty() { - * var empty = ''; - * var needit = []; - * var values = {}; - * - * // embed if-conditions from php - * <?=$checkFilledJS?> - * - * $("#empty-fields").html(empty); // render empty fields - * - * // console.log(JSON.stringify(values)); - * - * return { need : needit, data: values }; // return all fields - * } - * reportEmpty(); - * - * $('form').on('keyup change paste', 'input, select, textarea', function(){ - * console.log('Form changed!'); - * reportEmpty(); - * }); - * - * // validation? - * // check: https://www.sitepoint.com/instant-validation/ - * - * - * $('#post-form').on('submit', function(e){ - * e.preventDefault(); - * if (!waitingResponse) { - * waitingResponse = true; - * var resp = reportEmpty(); - * - * if (resp.need.length > 0) alert("Tα πεδία:\n\n" + resp.need.join(',\n') + "\n\nείναι υποχρεωτικά!"); - * else { - * // alert('sending: '+JSON.stringify(resp.data)); - * var postUrl = "/ajax.php?do=additem"; // url to post form - * var data2send = resp.data; // parse data to send - * - * $.ajax({ - * type: 'POST', - * url: postUrl, // make sure you respect the same origin policy with this url - * data: data2send, - * dataType: "text", - * - * success: function(data) { // server replies - * var json = $.parseJSON(data); - * if (json.success == true) { // good! post accepted - * // alert(json.id) - * window.location.href = '/ui-show-item.php?id='+ json.id; - * } - * else { - * alert("Post not accepted.\nPlease check the data you submit."); - * // $('#oc-company-form')[0].reset(); - * } - * }, - * - * error: function() { - * alert('Some ajax error! :('); - * } - * }); - * } - * - * waitingResponse = false; - * } - * - * }); - * - * <?php - * // bibliography and References - * // - * // WHICH JQUERY: - * // read: https://jquery.com/download/ - * // - * // SELECT2 - * // https://stackoverflow.com/questions/12889309/get-selected-value-from-multi-value-select-boxes-by-jquery-select2 - * // - * // tests: - * // https://jsfiddle.net/3nd1gL8o/1/ - * // https://jsfiddle.net/3nd1gL8o/5/ - * // - * // EXAMPLE with ALL CASES NEEDed: - * // https://jsfiddle.net/v684h0g2/2/ - * ?> - * </script> - * </body> - * </html> - */ diff --git a/public/app/views/components/header_includes.php b/public/app/views/components/header_includes.php index 9e1d239..ab16da1 100644 --- a/public/app/views/components/header_includes.php +++ b/public/app/views/components/header_includes.php @@ -58,9 +58,11 @@ <!-- basic cookie handling (vanilla js) --> <script src="/assets/js/cookie.js"></script> +<?php if (!$no_pdfmake) : ?> <!-- pdfmake --> -<script src="<?=SITE_URL?>/assets/js/pdfmake/pdfmake.min.js"></script> -<script src="<?=SITE_URL?>/assets/js/pdfmake/vfs_fonts.js"></script> + <script src="<?=SITE_URL?>/assets/js/pdfmake/pdfmake.min.js"></script> + <script src="<?=SITE_URL?>/assets/js/pdfmake/vfs_fonts.js"></script> +<?php endif; ?> <?php if (!$no_dataTables) : ?> <!-- DataTables js --> diff --git a/public/app/views/error/404.php b/public/app/views/error/404.php index 41f17da..95ec039 100644 --- a/public/app/views/error/404.php +++ b/public/app/views/error/404.php @@ -21,6 +21,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=$error_code?> : <?= $moto ?? 'Not found' ?></title> <style> diff --git a/public/app/views/error/general.php b/public/app/views/error/general.php index 6ed984b..28a1531 100644 --- a/public/app/views/error/general.php +++ b/public/app/views/error/general.php @@ -18,6 +18,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title> <?= isset($title) ? (SITE_TITLE .": ". $title) diff --git a/public/app/views/group.php b/public/app/views/group.php deleted file mode 100644 index 5d5dea0..0000000 --- a/public/app/views/group.php +++ /dev/null @@ -1,13 +0,0 @@ -<section> - <div style="padding: 1em"> - - <?php foreach ($group as $item) : ?> - - <div style="padding: 1em"> - <?php render_view('item', ['item' => $item]) ?> - </div> - - <?php endforeach; ?> - - </div> -</section> diff --git a/public/app/views/item.php b/public/app/views/item.php deleted file mode 100644 index 2354c81..0000000 --- a/public/app/views/item.php +++ /dev/null @@ -1,4 +0,0 @@ -<h3><?=$item['title']?></h3> -<p> - <i><?=$item['info']?></i> -</p>
\ No newline at end of file diff --git a/public/app/views/templates/admin_petitions.php b/public/app/views/templates/admin_petitions.php index 59c85f6..2a8479d 100644 --- a/public/app/views/templates/admin_petitions.php +++ b/public/app/views/templates/admin_petitions.php @@ -2,11 +2,12 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Control Panel</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes'); + Render::view('components/header_includes', [ 'no_pdfmake' => true ]); ?> <style> :root { /* login-form overides */ diff --git a/public/app/views/templates/admin_users.php b/public/app/views/templates/admin_users.php index baa2e58..1fc7cc7 100644 --- a/public/app/views/templates/admin_users.php +++ b/public/app/views/templates/admin_users.php @@ -2,11 +2,12 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Control Panel</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes'); + Render::view('components/header_includes', [ 'no_pdfmake' => true ]); ?> <style> :root { /* login-form overides */ diff --git a/public/app/views/templates/application.php b/public/app/views/templates/application.php index 72c9251..533a0bf 100644 --- a/public/app/views/templates/application.php +++ b/public/app/views/templates/application.php @@ -2,6 +2,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Αίτηση</title> <?php // header includes diff --git a/public/app/views/templates/create_pdf.php b/public/app/views/templates/create_pdf.php index 6b5c164..2549cda 100644 --- a/public/app/views/templates/create_pdf.php +++ b/public/app/views/templates/create_pdf.php @@ -2,6 +2,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?></title> <style> diff --git a/public/app/views/templates/invite.php b/public/app/views/templates/invite.php index ab0f12c..25826ec 100644 --- a/public/app/views/templates/invite.php +++ b/public/app/views/templates/invite.php @@ -2,11 +2,14 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Είσοδος Χρήστη</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes'); + Render::view('components/header_includes', + [ 'no_dataTables' => true, 'no_pdfmake' => true ] + ); ?> <style> :root { /* login-form overides */ diff --git a/public/app/views/templates/penalty.php b/public/app/views/templates/penalty.php index 232e8a8..a033925 100644 --- a/public/app/views/templates/penalty.php +++ b/public/app/views/templates/penalty.php @@ -2,6 +2,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Πρακτικό Πειθαρχικής Υπόθεσης</title> <?php // header includes diff --git a/public/app/views/user/control.php b/public/app/views/user/control.php index b429dc6..233e278 100644 --- a/public/app/views/user/control.php +++ b/public/app/views/user/control.php @@ -2,6 +2,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Control Panel</title> <?php // header includes diff --git a/public/app/views/user/invitation.php b/public/app/views/user/invitation.php index 64e5bcb..3544b90 100644 --- a/public/app/views/user/invitation.php +++ b/public/app/views/user/invitation.php @@ -2,6 +2,7 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Εγγραφή</title> <?php // header includes diff --git a/public/app/views/user/login.php b/public/app/views/user/login.php index 169a72b..54972df 100644 --- a/public/app/views/user/login.php +++ b/public/app/views/user/login.php @@ -2,11 +2,14 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Είσοδος Χρήστη</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes', [ 'no_dataTables' => true ]); + Render::view('components/header_includes', + [ 'no_dataTables' => true, 'no_pdfmake' => true ] + ); ?> <style> :root { /* login-form overides */ diff --git a/public/app/views/user/panel.php b/public/app/views/user/panel.php index 304237b..a371852 100644 --- a/public/app/views/user/panel.php +++ b/public/app/views/user/panel.php @@ -2,11 +2,12 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Control Panel</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes'); + Render::view('components/header_includes', [ 'no_pdfmake' => true ]); ?> <style> :root { /* login-form overides */ diff --git a/public/app/views/user/update_password.php b/public/app/views/user/update_password.php index b415f7c..ee91390 100644 --- a/public/app/views/user/update_password.php +++ b/public/app/views/user/update_password.php @@ -2,11 +2,14 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Αλλαγή Password</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes', [ 'no_dataTables' => true ]); + Render::view('components/header_includes', + [ 'no_dataTables' => true, 'no_pdfmake' => true ] + ); ?> </head> <body class="office central-form"> diff --git a/public/app/views/user/update_properties.php b/public/app/views/user/update_properties.php index 363016a..4af5bfe 100644 --- a/public/app/views/user/update_properties.php +++ b/public/app/views/user/update_properties.php @@ -2,11 +2,14 @@ <html lang="en"> <head> <meta charset="utf-8"> + <meta name="viewport" content="width=device-width initial-scale=1"> <title><?=SITE_TITLE?> - Ενημέρωση στοιχείων</title> <?php // header includes //////////////////////////////////////////////////////////////////////// - Render::view('components/header_includes'); + Render::view('components/header_includes', + [ 'no_dataTables' => true, 'no_pdfmake' => true ] + ); ?> </head> <body class="office central-form"> diff --git a/public/app/views/welcome.php b/public/app/views/welcome.php deleted file mode 100644 index fd3f703..0000000 --- a/public/app/views/welcome.php +++ /dev/null @@ -1,280 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <title>Welcome!</title> - - <!-- Latest compiled and minified CSS --> - <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"> - - <!-- jQuery library --> - <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.4/dist/jquery.slim.min.js"></script> - - <!-- select2 --> - <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> - <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> - - <style> -label { font-size:12px; } -.col, .col-1, .col-10, .col-11, .col-12, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9 { padding-left: 0; } -.form-group { margin-bottom: .667rem; } -select { height: 31px; padding-left: 8px; padding-right: 24px; } -select, input, -select option { font-size: .87rem; } - </style> - -</head> -<body class='classroom'> - <div class="container" style="max-width: 640px;"> - <div class="row"> - -<?php - $form = JsonToForm::make_a_form(REGISTRATION_FORM); -?> -<?=$form['html']?> - - </div> - </div> - - - -<script> -// NOW RUN EVERYTHING AFTER JQUERY (AND DOM ready) -// ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// - -// 00. FLAGS and NEEDED FUNCTIONS -// --------------------------------------------------------------------------- -////////////////////////////////////////////////////////////////////////////// - -var waitingResponse = false; // flag for an ajax request that was sent and still waiting response - -// pure JS ajax GET request -// return data as JSON -// no fancy things like UTF8; if needed use base64 --------------------------- -function ajax_get(url, callback) { - var xmlhttp = new XMLHttpRequest(); - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - - try { - var data = JSON.parse(xmlhttp.responseText); - } catch(err) { - console.log(err.message + ' in ' + xmlhttp.responseText); - return; - } - callback(data); - } - }; - - xmlhttp.open("GET", url, true); - xmlhttp.send(); -} - - -// 01. MENU MANAGEMENT -// --------------------------------------------------------------------------- -////////////////////////////////////////////////////////////////////////////// - -// menu management -// --------------------------------------------------------------------------- -$('.dropdown-item').on('click', function(e){ - e.preventDefault(); - - if (!waitingResponse) { - waitingResponse = true; - - var r = confirm('Δεν έχετε αποθηκεύσει το τρέχον αντικείμενο!\nΕίστε σίγουροι ότι θέλετε να εγκαταλείψετε τη σελίδα;'); - if (r == true) { - - // all data-goto have the format: 'method,uri_address' - // uri_address is the url to call - // method options: - // * url : means goto url (redirect) - // * ajax : means call url via ajax; if 'success = true' then goto '/' after that - // ----------------------------------------------------------------------- - var opt = $(this).data('goto').split(','); // split data-goto - - if (opt[0] == 'url') { // if method = url - window.location.href = opt[1]; - } - else { // else, method = ajax - ajax_get(opt[1], function(response) { - if (response.success) { - window.location.href = '/'; - } - }); - } - - } - else { - // user did not confirmed the selection; do nothing - } - - waitingResponse = false; - } - -}); - -// 02. USER INTERFACE -// --------------------------------------------------------------------------- -////////////////////////////////////////////////////////////////////////////// - -// tabs to accorderon -------------------------------------------------------- -////////////////////////////////////////////////////////////////////////////// - -// FUNCTION: Set tabsContainer height -// acording to which tab is visible -// and tab mode (tabs|acordeon) -// --------------------------------------------------------------------------- -function set_tabsContainer_height() { - var ch_; // content height - var tc_base; // tabs-container base height - tc_base = ($(window).width() > 650) ? 100 : 400; - if ($('#content1').is(':visible')) ch_ = $('#content1').height(); - if ($('#content2').is(':visible')) ch_ = $('#content2').height(); - if ($('#content3').is(':visible')) ch_ = $('#content3').height(); - if ($('#content4').is(':visible')) ch_ = $('#content4').height(); - if ($('#content5').is(':visible')) ch_ = $('#content5').height(); - if ($('#content6').is(':visible')) ch_ = $('#content6').height(); - - $('#tabsContainer').height(ch_ + tc_base); - -} -set_tabsContainer_height(); // init (run for 1st time) - -// on tab selection -// calculate tabsContainer height -$('input:radio[name="tabs"]').change( function(){ - set_tabsContainer_height() -}); - -// on window change -// set tabsContainer height -$( window ).resize(function() { - set_tabsContainer_height(); -}); - - - -// 03. FORM-CONTROLS -// --------------------------------------------------------------------------- -////////////////////////////////////////////////////////////////////////////// - -// Select2 controls -////////////////////////////////////////////////////////////////////////////// - -// FUNCTION: Get selected value(s) of Select2 control -// pass arg: source-element -// return: 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; -} - -// patch select2-multiple widths -// --------------------------------------------------------------------------- -$('.select-field').select2({ width: '100%' }); - -// init select2 fields -// (embed from php) -// --------------------------------------------------------------------------- -<?=$form['init_js']?> - -<?=$form['values_js']?> - - -// 04. FORM-LOGIC -// --------------------------------------------------------------------------- -////////////////////////////////////////////////////////////////////////////// - -// FUNCTION: Report empty fields -// --------------------------------------------------------------------------- -function reportEmpty() { - var empty = ''; - var needit = []; - var values = {}; - - // embed if-conditions from php - <?=$form['values_js']?> - - $("#empty-fields").html(empty); // render empty fields - - // console.log(JSON.stringify(values)); - - return { need : needit, data: values }; // return all fields -} -reportEmpty(); - -$('form').on('keyup change paste', 'input, select, textarea', function(){ - console.log('Form changed!'); - reportEmpty(); -}); - -// validation? -// check: https://www.sitepoint.com/instant-validation/ - - -$('#post-form').on('submit', function(e){ - e.preventDefault(); - if (!waitingResponse) { - waitingResponse = true; - var resp = reportEmpty(); - - if (resp.need.length > 0) alert("Tα πεδία:\n\n" + resp.need.join(',\n') + "\n\nείναι υποχρεωτικά!"); - else { - // alert('sending: '+JSON.stringify(resp.data)); - var postUrl = "/ajax.php?do=additem"; // url to post form - var data2send = resp.data; // parse data to send - - $.ajax({ - type: 'POST', - url: postUrl, // make sure you respect the same origin policy with this url - data: data2send, - dataType: "text", - - success: function(data) { // server replies - var json = $.parseJSON(data); - if (json.success == true) { // good! post accepted - // alert(json.id) - window.location.href = '/ui-show-item.php?id='+ json.id; - } - else { - alert("Post not accepted.\nPlease check the data you submit."); - // $('#oc-company-form')[0].reset(); - } - }, - - error: function() { - alert('Some ajax error! :('); - } - }); - } - - waitingResponse = false; - } - -}); - -</script> - - - - </body> -</html> - - |
