Chutier link from audio player cartel is working git add .
This commit is contained in:
@@ -1,5 +1,63 @@
|
||||
(function ($, Drupal) {
|
||||
|
||||
|
||||
function init(){
|
||||
console.log('Studio Init');
|
||||
initEvents();
|
||||
initAjax();
|
||||
};
|
||||
|
||||
function initEvents(){
|
||||
$('body').on('new-audio-cartel-loaded', initAjax);
|
||||
};
|
||||
|
||||
function initAjax(){
|
||||
console.log('studio initAjax chutier');
|
||||
$('.chutier-ajax-link:not(.ajax-enabled)')
|
||||
.addClass('ajax-enabled')
|
||||
.on('click', onClickAjaxLink);
|
||||
};
|
||||
|
||||
function onClickAjaxLink(e){
|
||||
console.log('studio onClickAjaxLink chutier');
|
||||
e.preventDefault();
|
||||
// var $this = $(this);
|
||||
addRemoveToChutier($(this));
|
||||
// switch($this.attr('action')){
|
||||
// case 'add':
|
||||
// // TODO: get target chutier
|
||||
// addToChutier($this);
|
||||
// break;
|
||||
// case 'remove':
|
||||
// // TODO: if we use more than one chutoer per user get target chutier
|
||||
// removeFromChutier($this);
|
||||
// break;
|
||||
// }
|
||||
return false;
|
||||
};
|
||||
|
||||
function addRemoveToChutier($link){
|
||||
// var ajax_path = 'edlp_studio/ajax/chutier/add/'+id; // + '/' +cid;
|
||||
var ajax_path = $link.attr('data-drupal-link-system-path');
|
||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||
$link.addClass('ajax-loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onActionToChutierDone($link, data);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorActionToChutier(jqxhr, textStatus, error, $link);
|
||||
});
|
||||
};
|
||||
|
||||
function onActionToChutierDone($link, data){
|
||||
console.log('onActionToChutierDone',data);
|
||||
$link.replaceWith(data.new_link);
|
||||
initAjax();
|
||||
};
|
||||
|
||||
function onErrorActionToChutier(jqxhr, textStatus, error, $link){
|
||||
console.warn('add to chuttier load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
init();
|
||||
})(jQuery, Drupal);
|
||||
|
||||
Reference in New Issue
Block a user