studio chutier is updating when documents added or removed, also added remove link in document list
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
(function ($, Drupal) {
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
var settings = drupalSettings.edlp_studio;
|
||||
|
||||
function init(){
|
||||
console.log('Studio Init');
|
||||
initEvents();
|
||||
initAjax();
|
||||
initAjaxChutier();
|
||||
};
|
||||
|
||||
function initEvents(){
|
||||
$('body').on('new-audio-cartel-loaded', initAjax);
|
||||
$('body')
|
||||
.on('new-audio-cartel-loaded', initAjaxChutier)
|
||||
.on('new-content-ajax-loaded', initAjaxChutier);
|
||||
};
|
||||
|
||||
function initAjax(){
|
||||
|
||||
// ___ _ _ _ _ _ _ _ _ _
|
||||
// / __| |_ _ _| |_(_)___ _ _ | \| |___ __| |___ | | (_)_ _ | |__ ___
|
||||
// | (__| ' \ || | _| / -_) '_| | .` / _ \/ _` / -_) | |__| | ' \| / /(_-<
|
||||
// \___|_||_\_,_|\__|_\___|_| |_|\_\___/\__,_\___| |____|_|_||_|_\_\/__/
|
||||
|
||||
function initAjaxChutier(){
|
||||
console.log('studio initAjax chutier');
|
||||
$('.chutier-ajax-link:not(.ajax-enabled)')
|
||||
.addClass('ajax-enabled')
|
||||
.on('click', onClickAjaxLink);
|
||||
.on('click', onClickChutierAjaxLink);
|
||||
};
|
||||
|
||||
function onClickAjaxLink(e){
|
||||
function onClickChutierAjaxLink(e){
|
||||
console.log('studio onClickAjaxLink chutier');
|
||||
e.preventDefault();
|
||||
addRemoveToChutier($(this));
|
||||
@@ -47,7 +57,8 @@
|
||||
'target_id':$link.attr('target_id'),
|
||||
});
|
||||
$link.replaceWith(data.new_link);
|
||||
initAjax();
|
||||
initAjaxChutier();
|
||||
updateStudioChutier();
|
||||
// TODO: reload Studio chutier_ui's documents list
|
||||
};
|
||||
|
||||
@@ -55,5 +66,41 @@
|
||||
console.warn('add to chuttier load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
|
||||
// ___ _ _ _ _
|
||||
// / __| |_ _ _ __| (_)___ ___ _ _(_)
|
||||
// \__ \ _| || / _` | / _ \___| || | |
|
||||
// |___/\__|\_,_\__,_|_\___/ \_,_|_|
|
||||
// this seems dirty
|
||||
function updateStudioChutier(){
|
||||
$studioChutier = $('#studio-ui .chutier_ui');
|
||||
if($studioChutier.length){
|
||||
var ajax_path = settings.chutier_ui_ajax;
|
||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||
$studioChutier.addClass('loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onLoadedChutier($studioChutier, data);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onLoadChutierError(jqxhr, textStatus, error, $studioChutier);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function onLoadedChutier($studioChutier, data){
|
||||
$studioChutier.replaceWith(data.rendered);
|
||||
initAjaxChutier();
|
||||
$('body').trigger({
|
||||
'type':'on-studio-chutier-updated'
|
||||
});
|
||||
}
|
||||
|
||||
function onLoadChutierError(jqxhr, textStatus, error, $studioChutier){
|
||||
console.warn('Chutier load failed', jqxhr.responseText);
|
||||
$studioChutier.removeClass('loading');
|
||||
|
||||
}
|
||||
|
||||
init();
|
||||
})(jQuery, Drupal);
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
|
||||
Reference in New Issue
Block a user