summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/DataTables/localization/Greek.json29
-rw-r--r--public/assets/js/panel/info.js1
-rw-r--r--public/assets/js/panel/own_petitions.js183
3 files changed, 213 insertions, 0 deletions
diff --git a/public/assets/js/DataTables/localization/Greek.json b/public/assets/js/DataTables/localization/Greek.json
new file mode 100644
index 0000000..a92f6cf
--- /dev/null
+++ b/public/assets/js/DataTables/localization/Greek.json
@@ -0,0 +1,29 @@
+
+
+{
+ "sDecimal": ",",
+ "sEmptyTable": "Δεν υπάρχουν δεδομένα στον πίνακα",
+ "sInfo": "Εμφανίζονται _START_ έως _END_ από _TOTAL_ εγγραφές",
+ "sInfoEmpty": "Εμφανίζονται 0 έως 0 από 0 εγγραφές",
+ "sInfoFiltered": "(φιλτραρισμένες από _MAX_ συνολικά εγγραφές)",
+ "sInfoPostFix": "",
+ "sInfoThousands": ".",
+ "sLengthMenu": "Εμφάνιση _MENU_ εγγραφών",
+ "sLoadingRecords": "Φόρτωση...",
+ "sProcessing": "Επεξεργασία...",
+ "sSearch": "Αναζήτηση:",
+ "sSearchPlaceholder": "Αναζήτηση",
+ "sThousands": ".",
+ "sUrl": "",
+ "sZeroRecords": "Δεν βρέθηκαν εγγραφές που να ταιριάζουν",
+ "oPaginate": {
+ "sFirst": "Πρώτη",
+ "sPrevious": "<",
+ "sNext": ">",
+ "sLast": "Τελευταία"
+ },
+ "oAria": {
+ "sSortAscending": ": ενεργοποιήστε για αύξουσα ταξινόμηση της στήλης",
+ "sSortDescending": ": ενεργοποιήστε για φθίνουσα ταξινόμηση της στήλης"
+ }
+}
diff --git a/public/assets/js/panel/info.js b/public/assets/js/panel/info.js
new file mode 100644
index 0000000..d046e1f
--- /dev/null
+++ b/public/assets/js/panel/info.js
@@ -0,0 +1 @@
+// null \ No newline at end of file
diff --git a/public/assets/js/panel/own_petitions.js b/public/assets/js/panel/own_petitions.js
new file mode 100644
index 0000000..84121e6
--- /dev/null
+++ b/public/assets/js/panel/own_petitions.js
@@ -0,0 +1,183 @@
+// Globals
+// -----------------------------------------------------------------------------
+var petitions = [];
+var table;
+
+
+
+// Supplamentary functions
+// -----------------------------------------------------------------------------
+
+// array.indexOf polyfill
+// --- -- -- - - -
+if (!Array.prototype.indexOf)
+{
+ Array.prototype.indexOf = function(elt /*, from*/)
+ {
+ var len = this.length >>> 0;
+
+ var from = Number(arguments[1]) || 0;
+ from = (from < 0)
+ ? Math.ceil(from)
+ : Math.floor(from);
+ if (from < 0)
+ from += len;
+
+ for (; from < len; from++)
+ {
+ if (from in this &&
+ this[from] === elt)
+ return from;
+ }
+ return -1;
+ };
+}
+
+
+// return petitions record by petition-id
+// --- -- -- - - -
+function petition_record(id) {
+ var record = false;
+ petitions.forEach(el => { if (el.id == id) record = el; });
+
+ return record;
+}
+
+
+// create actions html (edit and delete buttons)
+// --- -- -- - - -
+function create_actions_html(signature) {
+
+ var del, edit, show;
+
+ del = "";
+ edit = "";
+
+ show = [
+ '<a type="button" target="_blank" class="btn btn-xs btn-warning"',
+ 'href="/petition/signature/'+ signature +'">',
+ '<i class="fa-regular fa-circle-down"></i>',
+ '</a>'
+ ].join('\n');
+
+ return show +' '+ edit +' '+ del;
+}
+
+
+
+$(document).ready(function() {
+
+ // When document is ready
+ // -------------------------------------------------------------------------
+
+
+ /** init_table
+ * --- -- -- - - -
+ * get categories
+ * constuct categories array
+ * render dataTable
+ */
+ function init_table() {
+
+ // get all categories from server (ajax)
+ $.getJSON( "/user/get/petitions")
+ .done(function( json ) {
+ // then ...
+ console.log(json);
+
+ // reset categories
+ petitions.length = 0;
+
+ // construct petitions data
+ json.data.forEach( el => {
+ petitions.push({
+ id: parseInt(el.id),
+ subject: el.subject,
+ protocol: el.protocol,
+ signature: el.signature,
+ datepost: el.creation_date,
+ actions: create_actions_html(el.signature)
+ });
+ });
+
+
+ // destroy previous datatable table instances
+ $('#dt-petitions').dataTable().fnClearTable();
+ $('#dt-petitions').dataTable().fnDestroy();
+
+ // (re-)create categories datatable
+ table = $('#dt-petitions').DataTable({
+ language: { url: '/assets/js/DataTables/localization/Greek.json' },
+ data: petitions,
+ // ordering: false,
+ columns: [
+ { data: 'subject', width: '55%' },
+ { data: 'protocol' },
+ // { data: 'signature' },
+ { data: 'datepost' },
+ { data: 'actions' }
+ ]
+ });
+
+ })
+ .fail(function( jqxhr, textStatus, error ) {
+ console.log( "Request Failed (" + error +")" );
+ });
+
+ }
+ init_table(); // init table on first run
+
+
+
+ /** When modal show-up
+ * -------------------------------------------------------------------------
+ * ... prepare the manage-category form
+ * ... update select2 with possible parents
+ */
+ $('#manageCategory').on('show.bs.modal', event => {
+ var button = $(event.relatedTarget); // Button that triggered the modal
+ var id = parseInt( button.data('id') ); // category_id from data-id
+ // var modal = $(this); // modal object
+
+ // update modal literature
+ // ---
+ $('#manageCategory .modal-title').html( // modal title
+ (id) ? 'Ενημέρωση Κατηγορίας' : 'Δημιουργία Κατηγορίας'
+ );
+ $('#manageCategory form input[name=id]').val( id ); // category id (hidden)
+ $('#manageCategory form input[name=title]').val( // category title
+ (id) ? category_record(id).title : ""
+ );
+ prepare_parents_element(id); // prepare <select> for parents
+ })
+
+
+
+ // When form is submited
+ // -------------------------------------------------------------------------
+
+ $('#manageCategory form').submit( event => {
+ event.preventDefault();
+
+ // prepare data to POST
+ var data = {
+ id: parseInt($('#manageCategory form input[name=id]').val()),
+ title: $('#manageCategory form input[name=title]').val(),
+ parent_id: parseInt($('#parent_id').select2('data')[0].id)
+ };
+
+ // select action url (add or update)
+ var request = '/wiki/ajax?action=' + ((data.id == 0) ? 'add_category' : 'update_category');
+
+ // send POST request
+ $.post(request, data)
+ .done(function( data ) {
+
+ $('#manageCategory').modal('hide'); // when done, close modal
+
+ init_table(); // reload table of categories
+ });
+
+ });
+
+});