now diplaying composition list + new compo link which is working ajaxly
This commit is contained in:
@@ -5,23 +5,26 @@
|
||||
function init(){
|
||||
console.log('Studio Init');
|
||||
initEvents();
|
||||
initAjaxChutier();
|
||||
initAjaxLinks();
|
||||
};
|
||||
|
||||
function initEvents(){
|
||||
$('body')
|
||||
.on('new-audio-cartel-loaded', initAjaxChutier)
|
||||
.on('new-content-ajax-loaded', initAjaxChutier);
|
||||
.on('new-audio-cartel-loaded', initAjaxChutierLinks)
|
||||
.on('new-content-ajax-loaded', initAjaxLinks);
|
||||
};
|
||||
|
||||
|
||||
function initAjaxLinks(){
|
||||
initAjaxChutierLinks();
|
||||
initAjaxCompoLinks();
|
||||
}
|
||||
// ___ _ _ _ _ _ _ _ _ _
|
||||
// / __| |_ _ _| |_(_)___ _ _ | \| |___ __| |___ | | (_)_ _ | |__ ___
|
||||
// | (__| ' \ || | _| / -_) '_| | .` / _ \/ _` / -_) | |__| | ' \| / /(_-<
|
||||
// \___|_||_\_,_|\__|_\___|_| |_|\_\___/\__,_\___| |____|_|_||_|_\_\/__/
|
||||
|
||||
function initAjaxChutier(){
|
||||
console.log('studio initAjax chutier');
|
||||
function initAjaxChutierLinks(){
|
||||
console.log('studio initAjaxChutierLinks');
|
||||
$('.chutier-ajax-link:not(.ajax-enabled)')
|
||||
.addClass('ajax-enabled')
|
||||
.on('click', onClickChutierAjaxLink);
|
||||
@@ -57,13 +60,84 @@
|
||||
'target_id':$link.attr('target_id'),
|
||||
});
|
||||
$link.replaceWith(data.new_link);
|
||||
initAjaxChutier();
|
||||
initAjaxChutierLinks();
|
||||
// reload Studio chutier_ui's documents list
|
||||
updateStudioChutier();
|
||||
// TODO: reload Studio chutier_ui's documents list
|
||||
};
|
||||
|
||||
function onErrorActionToChutier(jqxhr, textStatus, error, $link){
|
||||
console.warn('add to chuttier load failed : '+error, jqxhr.responseText);
|
||||
console.warn('action to chuttier load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
// ___ _ _ _
|
||||
// / __|___ _ __ _ __ ___ __(_) |_(_)___ _ _ ___
|
||||
// | (__/ _ \ ' \| '_ \/ _ (_-< | _| / _ \ ' \(_-<
|
||||
// \___\___/_|_|_| .__/\___/__/_|\__|_\___/_||_/__/
|
||||
// |_|
|
||||
function initAjaxCompoLinks(){
|
||||
console.log('studio initAjaxCompoLinks');
|
||||
$('.new-composition-link:not(.ajax-enabled)')
|
||||
.addClass('ajax-enabled')
|
||||
.on('click', onClickCompoLink);
|
||||
};
|
||||
|
||||
function onClickCompoLink(e){
|
||||
e.preventDefault();
|
||||
setInputForNewCompoName($(this));
|
||||
return false;
|
||||
};
|
||||
|
||||
function setInputForNewCompoName($link){
|
||||
var $form = $('<form>').addClass('new-compo-form')
|
||||
.append($('<input>').attr('type', 'text').attr('placeholder', 'new name'))
|
||||
.append($('<button>').attr('type', 'submit').html('+'))
|
||||
.submit(function(e){
|
||||
onNewCompoFormSubmit(e, $link, $(this));
|
||||
});
|
||||
|
||||
$link
|
||||
.after($form)
|
||||
.addClass('folded');
|
||||
$form.children('input[type="text"]').focus();
|
||||
};
|
||||
|
||||
function onNewCompoFormSubmit(e, $link, $form){
|
||||
var name = $('input[type="text"]',$form).val();
|
||||
console.log('onNewCompoFormSubmit', name);
|
||||
if(name != ''){
|
||||
$form.addClass('ajax-loading').children('*').attr('disabled', 'disabled');
|
||||
createNewCompo(name, $link, $form);
|
||||
}
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
function createNewCompo(name,$link, $form){
|
||||
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, {
|
||||
'new_name':name
|
||||
})
|
||||
.done(function(data){
|
||||
onActionToCompoDone(data, $link, $form);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorActionToCompo(jqxhr, textStatus, error, $link);
|
||||
});
|
||||
};
|
||||
|
||||
function onActionToCompoDone(data, $link, $form){
|
||||
console.log('onActionToCompoDone',data);
|
||||
$link
|
||||
.removeClass('folded')
|
||||
.parents('li')
|
||||
.before($('<li>').append(data.new_link));
|
||||
$form.remove();
|
||||
// TODO: open new composition to composer
|
||||
};
|
||||
|
||||
function onErrorActionToCompo(jqxhr, textStatus, error, $link){
|
||||
console.warn('action to compo load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
|
||||
@@ -90,7 +164,7 @@
|
||||
|
||||
function onLoadedChutier($studioChutier, data){
|
||||
$studioChutier.replaceWith(data.rendered);
|
||||
initAjaxChutier();
|
||||
initAjaxChutierLinks();
|
||||
$('body').trigger({
|
||||
'type':'on-studio-chutier-updated'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user