From b594effb847b86fc6b1dae49d7948c46bba35e58 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Tue, 25 Apr 2023 16:45:03 +0300 Subject: alfa version; uploaded into test server (coder) --- public/assets/js/admin/edit_lesson.js | 17 ++-- public/assets/js/lesson-features.js | 164 ++++++++++++++++++++++++++++++++++ public/assets/js/post-features.js | 148 ------------------------------ 3 files changed, 174 insertions(+), 155 deletions(-) create mode 100644 public/assets/js/lesson-features.js delete mode 100644 public/assets/js/post-features.js (limited to 'public/assets/js') diff --git a/public/assets/js/admin/edit_lesson.js b/public/assets/js/admin/edit_lesson.js index 89e464f..fbcfabc 100644 --- a/public/assets/js/admin/edit_lesson.js +++ b/public/assets/js/admin/edit_lesson.js @@ -201,11 +201,14 @@ $(document).ready(function() { $('input[name=id]').val(lesson.id); // id $('input[name=title]').val(lesson.title); // title $('textarea[name=intro]').val(lesson.intro); // intro - $('textarea[name=body]').val(lesson.body); // body - $('input[name=status]').prop( // status - 'checked', - ((lesson.status==1)? true : false)) - .trigger('change'); + $('textarea[name=body]').val(lesson.body); // body + $('select[name=status]').val( + (lesson.status == 0) ? '0' : "one" + ).trigger('change'); + // $('input[name=status]').prop( // status + // 'checked', + // ((lesson.status==1)? true : false)) + // .trigger('change'); // $('#post-info').html('Δημιουργία: '+post.creation_date+'
Τελευταία Ενημέρωση: '+ post.update_date); @@ -408,8 +411,8 @@ $(document).ready(function() { // send POST (ajax) request $.post(request, data) .done(function( data ) { - console.log(data); - //window.location.href = '/admin/lessons'; // seems ok; bach to articles + // console.log(data); + window.location.href = '/admin/lessons'; // seems ok; bach to articles }); }); diff --git a/public/assets/js/lesson-features.js b/public/assets/js/lesson-features.js new file mode 100644 index 0000000..369c8f7 --- /dev/null +++ b/public/assets/js/lesson-features.js @@ -0,0 +1,164 @@ +const valid_codeblocks = [ // supported sort-code keys + 'youtube' +]; + + +const symbol_escapes = [ + { esc: '>', chr: '>' }, + { esc: '<', chr: '<' }, + { esc: '&', chr: '&' }, + { esc: '"', chr: '\"' }, + { esc: ''', chr: '\'' }, + { esc: '€', chr: '€' }, + { esc: '©', chr: '©' }, + { esc: '®', chr: '®' } +]; + + +var youtube_template = ( id => { + return '' +}); + +/* + + + + + + +*/ + + +/** inject_codeblocks + * --- -- -- - - - + * + * NOTE: + * a short-code is a mustache block of 3 parametres: + * {{ object = someID ; some label description }} + * ex. `{{product=1507175; Coca Cola Zero}}` + * + * The short-code is parsed to a code-block: + * an `a` modal-toggler link with certain data-attributes (+label), ex: + * `Coca Cola Zero` + * + * @param code (string): original content html with short-codes + * @returns (string): html content with code-blocks + */ +function inject_codeblocks(code) { + // isolate all mustache blocks + const regexp = /{{(.*?)}}/g; // regex makes multiple-matching easier + const matches = [...code.matchAll(regexp)]; + // console.log(matches); + + var output = code; // use a copy of (source) code + + matches.forEach( match => { + // parse (every) match + // NOTE: + // match array has 3 items; example: + // match[0] : `{{youtube=6EA-MIYY1bg}}` + // match[1] : `youtube=6EA-MIYY1bg` + // match[3] : the (source) code string + let blockparts = unescaped_str( match[1] ).trim().split('='); + let target = blockparts[0].toLowerCase(); + let id = blockparts[1]; + // let label = escaped_str(blockparts[1]); + if (valid_codeblocks.includes(target)) { + + if (target == 'youtube') { + var codeblock = youtube_template(id); + } + output = output.replaceAll(match[0], codeblock); + + } + }); + + return output; +} + + +// pair of function to escepe/unescape special html symbols +// --- -- -- - - - +function unescaped_str(txt) { + symbol_escapes.forEach( pair => { txt = txt.replaceAll(pair.esc, pair.chr); }) + return txt; +} + +function escaped_str(txt) { + symbol_escapes.forEach( pair => { txt = txt.replaceAll(pair.chr, pair.esc); }) + return txt; +} + + +$(document).ready(function() { + + + /** translate short-codes to code-blocks + * ------------------------------------------------------------------------- + */ + var content = $('.main-content .article-body').html(); // get code with shorts + $('.main-content .article-body').html( inject_codeblocks(content) ); // put code with blocks + + + + /** modal listeners + * ------------------------------------------------------------------------- + */ +/* DEPRICATED: not needed + // open store modal listener + // --- -- -- - - - + $(document).on('click', '.js-get_store', function (e) { + e.preventDefault(); + var id = $(this).data('id'); // id for requesting content via ajax + + $('#dynamic-content').html(''); + $('#modal-loader').show(); + + $.ajax({ + url: '/libs/modals/modalStore.php', + type: 'POST', + cache: false, + data: 'id=' + id, + dataType: 'html' + }) + .done(function (data) { + $('#dynamic-content').html(''); + $('#dynamic-content').html(data); + $('#modal-loader').hide(); + }) + .fail(function () { + $('#dynamic-content').html(' Υπήρξε κάποιο πρόβλημα, παρακαλώ προσπαθήστε ξανά.'); + $('#modal-loader').hide(); + }); + }); + + // open product modal listener + // --- + $(document).on('click', '.js-get_product', function (e) { + e.preventDefault(); + var id = $(this).data('id'); // id for requesting content via ajax + + $('#dynamic-product').html(''); + $('#modal-loader').show(); + + $.ajax({ + url: '/products/ajax/get_product_full', + cache: false, + type: 'POST', + data: { id: id }, + dataType: 'html' + }) + .done(function (data) { + $('#dynamic-product').html(''); + $('#dynamic-product').html(data); + $('#modal-loader').hide(); + + }) + .fail(function () { + $('#dynamic-product').html(' Υπήρξε κάποιο πρόβλημα, παρακαλώ προσπαθήστε ξανά.'); + $('#modal-loader').hide(); + + }); + }); +*/ +}); diff --git a/public/assets/js/post-features.js b/public/assets/js/post-features.js deleted file mode 100644 index ca2928c..0000000 --- a/public/assets/js/post-features.js +++ /dev/null @@ -1,148 +0,0 @@ -const valid_modals = [ // supported sort-code keys - 'product', - 'store' -]; - - -const symbol_escapes = [ - { esc: '>', chr: '>' }, - { esc: '<', chr: '<' }, - { esc: '&', chr: '&' }, - { esc: '"', chr: '\"' }, - { esc: ''', chr: '\'' }, - { esc: '€', chr: '€' }, - { esc: '©', chr: '©' }, - { esc: '®', chr: '®' } -]; - - -/** inject_codeblocks - * --- -- -- - - - - * - * NOTE: - * a short-code is a mustache block of 3 parametres: - * {{ object = someID ; some label description }} - * ex. `{{product=1507175; Coca Cola Zero}}` - * - * The short-code is parsed to a code-block: - * an `a` modal-toggler link with certain data-attributes (+label), ex: - * `Coca Cola Zero` - * - * @param code (string): original content html with short-codes - * @returns (string): html content with code-blocks - */ -function inject_codeblocks(code) { - // isolate all mustache blocks - const regexp = /{{(.*?)}}/g; // regex makes multiple-matching easier - const matches = [...code.matchAll(regexp)]; - // console.log(matches); - - var output = code; // use a copy of (source) code - - matches.forEach( match => { - // parse (every) match - // NOTE: - // match array has 3 items; example: - // match[0] : `{{store=247; Pasalimani Market}}` - // match[1] : `store=247; Pasalimani Market` - // match[3] : the (source) code string - let blockparts = unescaped_str( match[1] ).split(';'); - let main_unit = blockparts[0].replaceAll(' ','').split('='); - let target = main_unit[0].toLowerCase(); - let id = main_unit[1]; - let label = escaped_str(blockparts[1]); - if (valid_modals.includes(target)) { - let codeblock = `${label}`; - output = output.replaceAll(match[0], codeblock); - } - }); - - return output; -} - - -// pair of function to escepe/unescape special html symbols -// --- -- -- - - - -function unescaped_str(txt) { - symbol_escapes.forEach( pair => { txt = txt.replaceAll(pair.esc, pair.chr); }) - return txt; -} - -function escaped_str(txt) { - symbol_escapes.forEach( pair => { txt = txt.replaceAll(pair.chr, pair.esc); }) - return txt; -} - - -$(document).ready(function() { - - - /** translate short-codes to code-blocks - * ------------------------------------------------------------------------- - */ - var content = $('.content .article-body').html(); // get code with shorts - $('.content .article-body').html( inject_codeblocks(content) ); // put code with blocks - - - - /** modal listeners - * ------------------------------------------------------------------------- - */ - - // open store modal listener - // --- -- -- - - - - $(document).on('click', '.js-get_store', function (e) { - e.preventDefault(); - var id = $(this).data('id'); // id for requesting content via ajax - - $('#dynamic-content').html(''); - $('#modal-loader').show(); - - $.ajax({ - url: '/libs/modals/modalStore.php', - type: 'POST', - cache: false, - data: 'id=' + id, - dataType: 'html' - }) - .done(function (data) { - $('#dynamic-content').html(''); - $('#dynamic-content').html(data); - $('#modal-loader').hide(); - }) - .fail(function () { - $('#dynamic-content').html(' Υπήρξε κάποιο πρόβλημα, παρακαλώ προσπαθήστε ξανά.'); - $('#modal-loader').hide(); - }); - }); - - // open product modal listener - // --- - $(document).on('click', '.js-get_product', function (e) { - e.preventDefault(); - var id = $(this).data('id'); // id for requesting content via ajax - - $('#dynamic-product').html(''); - $('#modal-loader').show(); - - $.ajax({ - url: '/products/ajax/get_product_full', - cache: false, - type: 'POST', - data: { id: id }, - dataType: 'html' - }) - .done(function (data) { - $('#dynamic-product').html(''); - $('#dynamic-product').html(data); - $('#modal-loader').hide(); - - }) - .fail(function () { - $('#dynamic-product').html(' Υπήρξε κάποιο πρόβλημα, παρακαλώ προσπαθήστε ξανά.'); - $('#modal-loader').hide(); - - }); - }); - -}); \ No newline at end of file -- cgit v1.2.3