(function ($, Drupal, drupalSettings) { var _settings = drupalSettings.edlp_studio; var _$composer; // audio play is handled by edlp_theme function init(){ // console.log('Studio Init'); initEvents(); initStudio(); }; function initEvents(){ $('body') .on('new-audio-cartel-loaded', initAjaxChutierLinks) .on('new-content-ajax-loaded', initAjaxChutierLinks) .on('new-content-ajax-loaded', initStudio) .on('all-modal-closed', initStudio); }; function initStudio(){ if($('#studio-ui').length){ _$composer = $('.composition_ui .composer', '#studio-ui'); initAjaxChutierLinks(); initAjaxCompoLinks(); initDragAndDropUI(); initUsedChutierInCompo(); $('body').trigger({'type':'studio-initialized'}); }else{ $('body').trigger({'type':'studio-not-active'}); } } // ___ _ _ _ _ _ _ _ _ _ // / __| |_ _ _| |_(_)___ _ _ | \| |___ __| |___ | | (_)_ _ | |__ ___ // | (__| ' \ || | _| / -_) '_| | .` / _ \/ _` / -_) | |__| | ' \| / /(_-< // \___|_||_\_,_|\__|_\___|_| |_|\_\___/\__,_\___| |____|_|_||_|_\_\/__/ function initAjaxChutierLinks(){ //console.log('studio initAjaxChutierLinks'); $('.chutier-ajax-link:not(.ajax-enabled)') .addClass('ajax-enabled') .on('click', onClickChutierAjaxLink); }; function onClickChutierAjaxLink(e){ //console.log('studio onClickAjaxLink chutier'); e.preventDefault(); addRemoveToChutier($(this)); 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); $('body').trigger({ 'type':'chutier-action-done', 'action_done':data.action_done, 'new_action':data.action_done == 'add' ? 'remove' : 'add', 'target_id':$link.attr('target_id'), }); $link.replaceWith(data.new_link); initAjaxChutierLinks(); // reload Studio chutier_ui's documents list updateStudioChutier(); }; function onErrorActionToChutier(jqxhr, textStatus, error, $link){ console.warn('action to chuttier load failed : '+error, jqxhr.responseText); }; // ___ _ _ _ // / __|___ _ __ _ __ ___ __(_) |_(_)___ _ _ ___ // | (__/ _ \ ' \| '_ \/ _ (_-< | _| / _ \ ' \(_-< // \___\___/_|_|_| .__/\___/__/_|\__|_\___/_||_/__/ // |_| function initAjaxCompoLinks(){ //console.log('studio initAjaxCompoLinks'); $('.new-composition-link:not(.ajax-enabled)') .on('click', onClickNewCompoLink) .addClass('ajax-enabled'); $('.composition-link:not(.ajax-enabled)') .on('click', onClickCompoLink) .addClass('ajax-enabled'); $('.delete-composition-link:not(.ajax-enabled)') .on('click', onClickDeleteCompoLink) .addClass('ajax-enabled'); }; function initUsedChutierInCompo(){ console.log('initUsedChutierInCompo'); $('.chutier-link.on-compo', '#studio-ui .chutier_ui').removeClass('on-compo'); var nid; $('.audio-link', _$composer).each(function(index, el) { nid = $(el).attr('nid'); console.log('compo item', nid); $('.chutier-link[target_id="'+nid+'"]', '#studio-ui .chutier_ui').addClass('on-compo'); }); //audio-link }; // ___ ___ // / _ \ _ __ ___ _ _ / __|___ _ __ _ __ ___ // | (_) | '_ \/ -_) ' \ | (__/ _ \ ' \| '_ \/ _ \ // \___/| .__/\___|_||_| \___\___/_|_|_| .__/\___/ // |_| |_| function onClickCompoLink(e){ e.preventDefault(); //console.log('onClickCompoLink'); openCompo($(this)); return false; }; function openCompo($link){ var cid = $link.attr('cid'); var ajax_path = _settings.open_compo_ajax_url+'/'+cid; var path = window.location.origin + Drupal.url(ajax_path); $link.addClass('ajax-loading'); _$composer.addClass('ajax-loading'); $.getJSON(path, {}) .done(function(data){ onOpenCompoDone(data, $link); }) .fail(function(jqxhr, textStatus, error){ onErrorOpenCompo(jqxhr, textStatus, error, $link); }); }; function onOpenCompoDone(data, $link){ console.log('onOpenCompoDone',data); $('.composition-link').removeClass('is-active'); $link.removeClass('ajax-loading').addClass('is-active'); if($('.composition', _$composer).length){ $('.composition', _$composer).replaceWith(data.compo); }else{ $('header', _$composer).after(data.compo); } _$composer.removeClass('ajax-loading'); initDragAndDropUI(); initUsedChutierInCompo(); $('body').trigger({ 'type':'on-studio-compo-opened' }); }; function onErrorOpenCompo(jqxhr, textStatus, error, $link){ $link.removeClass('ajax-loading'); console.warn('open compo load failed : '+error, jqxhr.responseText); }; // _ _ _____ __ __ __ ___ _ __ _ __ ___ // | ' \/ -_) V V / / _/ _ \ ' \| '_ \/ _ \ // |_||_\___|\_/\_/ \__\___/_|_|_| .__/\___/ // |_| function onClickNewCompoLink(e){ e.preventDefault(); setInputForNewCompoName($(this)); return false; }; function setInputForNewCompoName($link){ var $form = $('