Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions lib/javascript/tools-extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@

//import notie from 'notie'

var utilsApiEnpoint = '//utils.dev/api/genre/add';
var currentData = {};
var previousEdit = '';
var currentForm = {};


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);
}

//assuming "b" contains a subsequence containing
//all of the letters in "a" in the same order
function getDifference(a, b)
{
var i = 0;
var j = 0;
var result = "";

while (j < b.length)
{
if (a[i] != b[j] || i == a.length)
result += b[j];
else
i++;
j++;
}
return result;
}

// Wait for element to exist.
function elementLoaded(el, cb) {
if ($(el).length) {
console.debug('elementLoaded');
cb($(el));
} else {
// Repeat every 500ms.
setTimeout(function() {
elementLoaded(el, cb)
}, 500);
}
}


// Wait for element gone.
function elementNotLoaded(el, cb) {
if (!$(el).length) {
console.debug('elementNotLoaded');
setTimeout(function() {
elementNotLoaded(el, cb)
}, 500);
} else {

cb($(el));
}
}

function searchElement() {
elementLoaded('.edit_dialog_content', function(el) {
// Element is ready to use.
currentForm = el;

//console.debug(currentForm.attr('id'));

currentData = getFormData(currentForm);
previousEdit = currentData.edit_tags;

notie.alert({ type: 2, text: 'Only Tags/Genres working now!', time: 5});
});
}

elementNotLoaded('.edit_dialog_content', function(el) {
searchElement();
});

searchElement();

/*
$(document).on('click', '.tagit-new', function(){

});
*/

$(document).on('click', ".ui-dialog-buttonset span:contains('Save')" , function() {
currentData = getFormData(currentForm);

//console.debug(previousEdit);
//console.debug(currentData.edit_tags);
//console.debug(getDifference(previousEdit, currentData.edit_tags));

$.getJSON(utilsApiEnpoint, {
edit_tags: typeof previousEdit == "undefined" ? currentData.edit_tags : getDifference(previousEdit, currentData.edit_tags),
object_id: currentData.id,
object_type: currentData.type.replace('_row', ''),
user: readCookie('ampache_user')
},
function(response) {

if (response.length) {

notie.alert({ type: 'success', text: 'Tune successfully Genred!', time: 2 }); // Hides after 2 seconds

$('#editdialog').dialog('close');

var reloadp = window.location;
var hash = window.location.hash.substring(1);
if (hash && hash.indexOf('.php') > -1) {
reloadp = jsWebPath + '/' + hash;
}
loadContentPage(reloadp);
searchElement();
}
},
function(error) {
notie.alert({ type: 3, text: 'Ouch... something goes wrong!', stay: true});
});

});
2 changes: 2 additions & 0 deletions lib/javascript/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down
18 changes: 11 additions & 7 deletions templates/header.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
<link rel="stylesheet" href="<?php echo $web_path; ?>/modules/jquery-mediaTable/jquery.mediaTable.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo $web_path; ?>/lib/components/datetimepicker/jquery.datetimepicker.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo $web_path; ?>/lib/components/jQuery-contextMenu/dist/jquery.contextMenu.min.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/notie/dist/notie.min.css">

<script src="<?php echo $web_path; ?>/lib/components/jquery/jquery.min.js" language="javascript" type="text/javascript"></script>
<script src="<?php echo $web_path; ?>/lib/components/jquery-ui/jquery-ui.min.js" language="javascript" type="text/javascript"></script>
<script src="<?php echo $web_path; ?>/lib/components/prettyphoto/js/jquery.prettyPhoto.js" language="javascript" type="text/javascript"></script>
Expand All @@ -79,6 +81,8 @@
<script src="<?php echo $web_path; ?>/lib/javascript/base.js" language="javascript" type="text/javascript"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/ajax.js" language="javascript" type="text/javascript"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/tools.js" language="javascript" type="text/javascript"></script>
<script src="https://unpkg.com/notie"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/tools-extend.js" language="javascript" type="text/javascript"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
Expand Down Expand Up @@ -290,7 +294,7 @@ function update_action()
}
});
</script>

<?php if (AmpConfig::get('cookie_disclaimer') && !isset($_COOKIE['cookie_disclaimer'])) {
?>
<script type="text/javascript" language="javascript">
Expand All @@ -308,7 +312,7 @@ function update_action()
</script>
<?php
} ?>

<?php if (AmpConfig::get('libitem_contextmenu')) {
?>
<script type="text/javascript" language="javascript">
Expand All @@ -317,14 +321,14 @@ function libitem_action(item, action)
var iinfo = item.attr('id').split('_', 2);
var object_type = iinfo[0];
var object_id = iinfo[1];

if (action !== undefined && action !== '') {
ajaxPut(jsAjaxUrl + action + '&object_type=' + object_type + '&object_id=' + object_id);
} else {
showPlaylistDialog(this, object_type, object_id);
}
}

$.contextMenu({
selector: ".libitem_menu",
items: {
Expand All @@ -338,7 +342,7 @@ function libitem_action(item, action)
</script>
<?php
} ?>

<!-- rfc3514 implementation -->
<div id="rfc3514" style="display:none;">0x0</div>
<div id="notification" class="notification-out"><img src="<?php echo $web_path; ?>/images/icon_info.png" /><span id="notification-content"></span></div>
Expand Down Expand Up @@ -484,7 +488,7 @@ function libitem_action(item, action)
<div id="ajax-loading">Loading . . .</div>
<div id="util_div" style="display:none;"></div>
<iframe name="util_iframe" id="util_iframe" style="display:none;" src="<?php echo $web_path; ?>/util.php"></iframe>

<div id="content" class="content-<?php echo AmpConfig::get('ui_fixed') ? (AmpConfig::get('topmenu') ? 'fixed-topmenu' : 'fixed') : 'float'; ?> <?php echo(($count_temp_playlist || AmpConfig::get('play_type') == 'localplay') ? '' : 'content-right-wild'); echo $isCollapsed ? ' content-left-wild' : ''; ?>">

<?php
Expand All @@ -495,7 +499,7 @@ function libitem_action(item, action)
echo '<br />';
}
$count_temp_playlist = count($GLOBALS['user']->playlist->get_items());

if (AmpConfig::get('int_config_version') != AmpConfig::get('config_version')) {
?>
<div class="fatalerror">
Expand Down