From c70d7afab844192f327eea83dab1ccbfc01ef650 Mon Sep 17 00:00:00 2001 From: rolla Date: Tue, 15 Aug 2017 02:29:28 +0300 Subject: [PATCH 1/2] Added: JS file to catch edit form actions; --- lib/javascript/tools-extend.js | 69 ++++++++++++++++++++++++++++++++++ lib/javascript/tools.js | 2 + templates/header.inc.php | 1 + 3 files changed, 72 insertions(+) create mode 100644 lib/javascript/tools-extend.js diff --git a/lib/javascript/tools-extend.js b/lib/javascript/tools-extend.js new file mode 100644 index 00000000000..a7e5f3fae14 --- /dev/null +++ b/lib/javascript/tools-extend.js @@ -0,0 +1,69 @@ + +function getFormData($form){ + var unindexed_array = $form.serializeArray(); + var indexed_array = {}; + + $.map(unindexed_array, function(n, i){ + indexed_array[n['name']] = n['value']; + }); + + return indexed_array; +} + +// Cookies +function createCookie(name, value, days) { + if (days) { + var date = new Date(); + if (days) {date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + var expires = "; expires=" + date.toGMTString(); + } + else var expires = ""; + + document.cookie = name + "=" + value + expires + "; path=/"; +} + +function readCookie(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1, c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + } + return null; +} + +function eraseCookie(name) { + createCookie(name, "", -1); +} + +$(document).on('click', '.tagit-new', function(){ + var utilsApiEnpoint = '//utils.dev/api/genre/add'; + var currentForm = $(this).closest('form.edit_dialog_content'); + var formId = currentForm.attr('id'); + + console.debug(formId); + //var tuneid = currentForm.find("input[name='id']"); + + //console.debug(getFormData(currentForm)); + + $( ".ui-dialog-buttonset span:contains('Save')" ).first().on('click', function(){ + var currentData = getFormData(currentForm); + + console.debug(getFormData(currentForm)); + + $.getJSON(utilsApiEnpoint, { + edit_tags: currentData.edit_tags, + object_id: currentData.id, + object_type: currentData.type.replace('_row', ''), + user: readCookie('ampache_user') + }, + function (response){ + console.debug(response) + }); + + }); + + //console.debug(currentForm.); +}) + diff --git a/lib/javascript/tools.js b/lib/javascript/tools.js index 7fdbf61e439..6dd9dd26e44 100644 --- a/lib/javascript/tools.js +++ b/lib/javascript/tools.js @@ -266,6 +266,7 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro parent.dialog_buttons = {}; this.dialog_buttons[jsSaveTitle] = function () { + /* $.ajax({ url: parent.saveUrl, type: 'POST', @@ -300,6 +301,7 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro $('#editdialog').dialog('close'); } }); + */ } this.dialog_buttons[jsCancelTitle] = function() { $('#editdialog').dialog('close'); diff --git a/templates/header.inc.php b/templates/header.inc.php index 19226080d57..37f8ed263b6 100644 --- a/templates/header.inc.php +++ b/templates/header.inc.php @@ -79,6 +79,7 @@ + @@ -79,6 +81,7 @@ + - + - + - +
@@ -485,7 +488,7 @@ function libitem_action(item, action)
Loading . . .
- +
'; } $count_temp_playlist = count($GLOBALS['user']->playlist->get_items()); - + if (AmpConfig::get('int_config_version') != AmpConfig::get('config_version')) { ?>