|
@@ -5,23 +5,26 @@
|
|
function init(){
|
|
function init(){
|
|
console.log('Studio Init');
|
|
console.log('Studio Init');
|
|
initEvents();
|
|
initEvents();
|
|
- initAjaxChutier();
|
|
|
|
|
|
+ initAjaxLinks();
|
|
};
|
|
};
|
|
|
|
|
|
function initEvents(){
|
|
function initEvents(){
|
|
$('body')
|
|
$('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)')
|
|
$('.chutier-ajax-link:not(.ajax-enabled)')
|
|
.addClass('ajax-enabled')
|
|
.addClass('ajax-enabled')
|
|
.on('click', onClickChutierAjaxLink);
|
|
.on('click', onClickChutierAjaxLink);
|
|
@@ -57,13 +60,84 @@
|
|
'target_id':$link.attr('target_id'),
|
|
'target_id':$link.attr('target_id'),
|
|
});
|
|
});
|
|
$link.replaceWith(data.new_link);
|
|
$link.replaceWith(data.new_link);
|
|
- initAjaxChutier();
|
|
|
|
|
|
+ initAjaxChutierLinks();
|
|
|
|
+ // reload Studio chutier_ui's documents list
|
|
updateStudioChutier();
|
|
updateStudioChutier();
|
|
- // TODO: reload Studio chutier_ui's documents list
|
|
|
|
};
|
|
};
|
|
|
|
|
|
function onErrorActionToChutier(jqxhr, textStatus, error, $link){
|
|
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){
|
|
function onLoadedChutier($studioChutier, data){
|
|
$studioChutier.replaceWith(data.rendered);
|
|
$studioChutier.replaceWith(data.rendered);
|
|
- initAjaxChutier();
|
|
|
|
|
|
+ initAjaxChutierLinks();
|
|
$('body').trigger({
|
|
$('body').trigger({
|
|
'type':'on-studio-chutier-updated'
|
|
'type':'on-studio-chutier-updated'
|
|
});
|
|
});
|