|
@@ -1,22 +1,25 @@
|
|
|
(function ($, Drupal, drupalSettings) {
|
|
|
|
|
|
var settings = drupalSettings.edlp_studio;
|
|
|
+ var composer;
|
|
|
|
|
|
function init(){
|
|
|
console.log('Studio Init');
|
|
|
initEvents();
|
|
|
- initAjaxLinks();
|
|
|
+ initStudio();
|
|
|
};
|
|
|
|
|
|
function initEvents(){
|
|
|
$('body')
|
|
|
.on('new-audio-cartel-loaded', initAjaxChutierLinks)
|
|
|
- .on('new-content-ajax-loaded', initAjaxLinks);
|
|
|
+ .on('new-content-ajax-loaded', initStudio);
|
|
|
};
|
|
|
|
|
|
- function initAjaxLinks(){
|
|
|
+ function initStudio(){
|
|
|
+ $composer = $('.composition_ui .composer', '#studio-ui');
|
|
|
initAjaxChutierLinks();
|
|
|
initAjaxCompoLinks();
|
|
|
+ initDragAndDropUI();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -29,14 +32,12 @@
|
|
|
.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 = $link.attr('data-drupal-link-system-path');
|
|
@@ -50,7 +51,6 @@
|
|
|
onErrorActionToChutier(jqxhr, textStatus, error, $link);
|
|
|
});
|
|
|
};
|
|
|
-
|
|
|
function onActionToChutierDone($link, data){
|
|
|
console.log('onActionToChutierDone',data);
|
|
|
$('body').trigger({
|
|
@@ -64,7 +64,6 @@
|
|
|
|
|
|
updateStudioChutier();
|
|
|
};
|
|
|
-
|
|
|
function onErrorActionToChutier(jqxhr, textStatus, error, $link){
|
|
|
console.warn('action to chuttier load failed : '+error, jqxhr.responseText);
|
|
|
};
|
|
@@ -77,18 +76,16 @@
|
|
|
function initAjaxCompoLinks(){
|
|
|
console.log('studio initAjaxCompoLinks');
|
|
|
$('.new-composition-link:not(.ajax-enabled)')
|
|
|
- .addClass('ajax-enabled')
|
|
|
- .on('click', onClickNewCompoLink);
|
|
|
+ .on('click', onClickNewCompoLink)
|
|
|
+ .addClass('ajax-enabled');
|
|
|
$('.composition-link:not(.ajax-enabled)')
|
|
|
- .addClass('ajax-enabled')
|
|
|
- .on('click', onClickCompoLink);
|
|
|
+ .on('click', onClickCompoLink)
|
|
|
+ .addClass('ajax-enabled');
|
|
|
$('.delete-composition-link:not(.ajax-enabled)')
|
|
|
- .addClass('ajax-enabled')
|
|
|
- .on('click', onClickDeleteCompoLink);
|
|
|
+ .on('click', onClickDeleteCompoLink)
|
|
|
+ .addClass('ajax-enabled');
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -97,21 +94,46 @@
|
|
|
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('onActionToCompoDone',data);
|
|
|
+ $('.composition-link').removeClass('is-active');
|
|
|
+ $link.removeClass('ajax-loading').addClass('is-active');
|
|
|
+
|
|
|
+ $composer.html(data.compo);
|
|
|
+ $composer.removeClass('ajax-loading');
|
|
|
+ initDragAndDropUI();
|
|
|
+ };
|
|
|
+ function onErrorOpenCompo(jqxhr, textStatus, error, $link){
|
|
|
+ $link.removeClass('ajax-loading');
|
|
|
+ console.warn('open compo load failed : '+error, jqxhr.responseText);
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
function onClickNewCompoLink(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'))
|
|
@@ -125,7 +147,6 @@
|
|
|
.addClass('folded');
|
|
|
$form.children('input[type="text"]').focus();
|
|
|
};
|
|
|
-
|
|
|
function onNewCompoFormSubmit(e, $link, $form){
|
|
|
var name = $('input[type="text"]',$form).val();
|
|
|
console.log('onNewCompoFormSubmit', name);
|
|
@@ -135,7 +156,6 @@
|
|
|
}
|
|
|
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;
|
|
@@ -144,14 +164,13 @@
|
|
|
'new_name':name
|
|
|
})
|
|
|
.done(function(data){
|
|
|
- onActionToCompoDone(data, $link, $form);
|
|
|
+ onCreateCompoDone(data, $link, $form);
|
|
|
})
|
|
|
.fail(function(jqxhr, textStatus, error){
|
|
|
- onErrorActionToCompo(jqxhr, textStatus, error, $link);
|
|
|
+ onErrorCreateCompo(jqxhr, textStatus, error, $link);
|
|
|
});
|
|
|
};
|
|
|
-
|
|
|
- function onActionToCompoDone(data, $link, $form){
|
|
|
+ function onCreateCompoDone(data, $link, $form){
|
|
|
console.log('onActionToCompoDone',data);
|
|
|
$link
|
|
|
.removeClass('folded')
|
|
@@ -160,12 +179,10 @@
|
|
|
$form.remove();
|
|
|
|
|
|
};
|
|
|
-
|
|
|
- function onErrorActionToCompo(jqxhr, textStatus, error, $link){
|
|
|
+ function onErrorCreateCompo(jqxhr, textStatus, error, $link){
|
|
|
console.warn('action to compo load failed : '+error, jqxhr.responseText);
|
|
|
};
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -223,7 +240,6 @@
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
function onLoadedChutier($studioChutier, data){
|
|
|
$studioChutier.replaceWith(data.rendered);
|
|
|
initAjaxChutierLinks();
|
|
@@ -231,12 +247,130 @@
|
|
|
'type':'on-studio-chutier-updated'
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
function onLoadChutierError(jqxhr, textStatus, error, $studioChutier){
|
|
|
console.warn('Chutier load failed', jqxhr.responseText);
|
|
|
$studioChutier.removeClass('loading');
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function initDragAndDropUI(){
|
|
|
+
|
|
|
+
|
|
|
+ $('.composition_ui .composer .composition .field--name-documents .field__item').each(function(i){
|
|
|
+ $(this).prepend($('<span>').addClass('handler'));
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ var $remove_zone = $('<div>').addClass('remove-drop-zone')
|
|
|
+ .appendTo('.composition_ui .composer .composition')
|
|
|
+ .droppable({
|
|
|
+ tolerance:'pointer',
|
|
|
+
|
|
|
+ over:function(e,ui){
|
|
|
+
|
|
|
+ ui.draggable.addClass('ready-to-remove');
|
|
|
+ },
|
|
|
+ out:function(e,ui){
|
|
|
+
|
|
|
+ ui.draggable.removeClass('ready-to-remove');
|
|
|
+ },
|
|
|
+ drop:function(e,ui){
|
|
|
+
|
|
|
+ ui.draggable.remove();
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $('.composition_ui .composer .composition .field--name-documents').sortable({
|
|
|
+ revert:false,
|
|
|
+ handle: ".handler",
|
|
|
+ receive:function(e, ui){
|
|
|
+ $('.field__item', this).attr('style', '');
|
|
|
+
|
|
|
+ },
|
|
|
+ update:function(e, ui){
|
|
|
+ onOrderChanged(e, ui);
|
|
|
+ },
|
|
|
+ connectWith : $remove_zone,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $('.chutier_ui .item-list li>div').draggable({
|
|
|
+ containment:$('#studio-ui'),
|
|
|
+ scroll:false,
|
|
|
+ helper:function(e){
|
|
|
+
|
|
|
+
|
|
|
+ return $('<div>').addClass('field__item')
|
|
|
+ .append(
|
|
|
+ $('<article>').addClass('node').append(
|
|
|
+ $('<h2>').addClass('node-title').append(
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $('.audio-link',this).clone().removeClass('ajax-enable')
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .prepend($('<span>').addClass('handler'));
|
|
|
+ },
|
|
|
+
|
|
|
+ cursorAt:{bottom:10,left:10},
|
|
|
+ zIndex:999,
|
|
|
+ revert:true,
|
|
|
+ revertDuration:0,
|
|
|
+ connectToSortable:$('.composition_ui .composer .composition .field--name-documents'),
|
|
|
+ });
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function onOrderChanged(e, ui){
|
|
|
+ console.log('onOrderChanged : e', e);
|
|
|
+
|
|
|
+ var documents = [];
|
|
|
+ $('a', e.target).each(function(i) {
|
|
|
+
|
|
|
+ documents.push($(this).attr('nid'));
|
|
|
+ });
|
|
|
+ console.log(documents);
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ function recordCompoList(cid, docs){
|
|
|
+ var ajax_path = 'path';
|
|
|
+ var path = window.location.origin + Drupal.url(ajax_path);
|
|
|
+ $.getJSON(path, {
|
|
|
+ documents:docs
|
|
|
+ })
|
|
|
+ .done(function(data){
|
|
|
+ onRecordCompoDone(data);
|
|
|
+ })
|
|
|
+ .fail(function(jqxhr, textStatus, error){
|
|
|
+ onErrorRecordCompo(jqxhr, textStatus, error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function onRecordCompoDone(data){
|
|
|
+ console.log('onDeleteCompoDone',data);
|
|
|
+ if(data.status == "ok"){
|
|
|
+ }else{
|
|
|
+ console.warn(data.message);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ function onErrorRecordCompo(jqxhr, textStatus, error){
|
|
|
+ console.warn('record compo failed : '+error, jqxhr.responseText);
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
init();
|
|
|
})(jQuery, Drupal, drupalSettings);
|