Bachir Soussi Chiadmi 6 лет назад
Родитель
Сommit
849ab4f4b0

+ 5 - 2
sites/all/modules/figli/edlp_studio/assets/js/edlp_studio.js

@@ -123,8 +123,11 @@
     console.log('onActionToCompoDone',data);
     $('.composition-link').removeClass('is-active');
     $link.removeClass('ajax-loading').addClass('is-active');
-
-    $('.composition', $composer).replaceWith(data.compo);
+    if($('.composition', $composer).length){
+      $('.composition', $composer).replaceWith(data.compo);
+    }else{
+      $('header', $composer).after(data.compo);
+    }
     $composer.removeClass('ajax-loading');
     initDragAndDropUI();
     $('body').trigger({

+ 6 - 3
sites/all/modules/figli/edlp_studio/includes/edlp_composition_ui.inc

@@ -3,9 +3,12 @@
 function template_preprocess_edlp_composition_ui(&$vars){
   // dpm($vars);
 
-
-  $view_builder = \Drupal::entityTypeManager()->getViewBuilder('composition');
-  $vars['composition'] = $view_builder->view($vars['lastcomposition'], 'studio_ui');
+  if($vars['lastcomposition']){
+    $view_builder = \Drupal::entityTypeManager()->getViewBuilder('composition');
+    $vars['composition'] = $view_builder->view($vars['lastcomposition'], 'studio_ui');
+  }else{
+    $vars['composition'] = null;
+  }
 
 
 }

+ 11 - 2
sites/all/modules/figli/edlp_studio/src/Controller/StudioUIController.php

@@ -135,7 +135,12 @@ class StudioUIController extends ControllerBase {
       ->condition('user_id', $this->user->id());
 
     $compos_ids = $query->execute();
-    $compos = entity_load_multiple('composition', $compos_ids);
+    // dpm($compos_ids);
+    if(count($compos_ids)){
+      $compos = entity_load_multiple('composition', $compos_ids);
+    }else{
+      $compos = array();
+    }
 
     $createurl = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action' => 'create'], ['absolute' => TRUE]);
 
@@ -154,7 +159,11 @@ class StudioUIController extends ControllerBase {
       ->sort('created');
 
     $compos_id = $query->execute();
-    $lastcompo = entity_load('composition', array_pop($compos_id));
+    if(count($compos_id)){
+      $lastcompo = entity_load('composition', array_pop($compos_id));
+    }else{
+      $lastcompo = null;
+    }
 
     return $lastcompo;
   }

+ 15 - 12
sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js

@@ -669,24 +669,27 @@
         console.log('CompoPlayer initControls()');
         this.$composer = $('.composition_ui .composer');
         this.$controls = $('.composition_ui .composer .compo-player-controls');
+        if(!this.$controls.is('.ready') && this.$compo){
+          this.$previous = $('<div>').addClass('previous')
+            .on('click', this.prev.bind(this))
+            .appendTo(this.$controls);
+          this.$playpause = $('<div>').addClass('play-pause')
+            .on('click', this.togglePlayPause.bind(this))
+            .appendTo(this.$controls);
+          this.$next = $('<div>').addClass('next')
+            .on('click', this.next.bind(this))
+            .appendTo(this.$controls);
 
-        this.$previous = $('<div>').addClass('previous')
-          .on('click', this.prev.bind(this))
-          .appendTo(this.$controls);
-        this.$playpause = $('<div>').addClass('play-pause')
-          .on('click', this.togglePlayPause.bind(this))
-          .appendTo(this.$controls);
-        this.$next = $('<div>').addClass('next')
-          .on('click', this.next.bind(this))
-          .appendTo(this.$controls);
+          this.$controls.addClass('ready');
 
-        this.active = true; // TODO: set active false
-
-        this.newCompo();
+          this.active = true; // TODO: set active false
+          this.newCompo();
+        }
       },
       newCompo(){
         console.log('CompoPlayer newCompo()');
         this.$compo = $('.composition_ui .composer .composition');
+        this.initControls();
         this.refresh();
       },
       refresh(){

+ 15 - 12
sites/all/themes/custom/edlptheme/assets/scripts/main.js

@@ -669,24 +669,27 @@
         console.log('CompoPlayer initControls()');
         this.$composer = $('.composition_ui .composer');
         this.$controls = $('.composition_ui .composer .compo-player-controls');
+        if(!this.$controls.is('.ready') && this.$compo){
+          this.$previous = $('<div>').addClass('previous')
+            .on('click', this.prev.bind(this))
+            .appendTo(this.$controls);
+          this.$playpause = $('<div>').addClass('play-pause')
+            .on('click', this.togglePlayPause.bind(this))
+            .appendTo(this.$controls);
+          this.$next = $('<div>').addClass('next')
+            .on('click', this.next.bind(this))
+            .appendTo(this.$controls);
 
-        this.$previous = $('<div>').addClass('previous')
-          .on('click', this.prev.bind(this))
-          .appendTo(this.$controls);
-        this.$playpause = $('<div>').addClass('play-pause')
-          .on('click', this.togglePlayPause.bind(this))
-          .appendTo(this.$controls);
-        this.$next = $('<div>').addClass('next')
-          .on('click', this.next.bind(this))
-          .appendTo(this.$controls);
+          this.$controls.addClass('ready');
 
-        this.active = true; // TODO: set active false
-
-        this.newCompo();
+          this.active = true; // TODO: set active false
+          this.newCompo();
+        }
       },
       newCompo(){
         console.log('CompoPlayer newCompo()');
         this.$compo = $('.composition_ui .composer .composition');
+        this.initControls();
         this.refresh();
       },
       refresh(){