From 849ab4f4b09c10e8eadd890df16ea998ad0bb4eb Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Tue, 27 Mar 2018 16:38:10 +0200 Subject: [PATCH] studio ui fix --- .../edlp_studio/assets/js/edlp_studio.js | 7 +++-- .../includes/edlp_composition_ui.inc | 9 ++++--- .../src/Controller/StudioUIController.php | 13 +++++++-- .../edlptheme/assets/dist/scripts/main.min.js | 27 ++++++++++--------- .../custom/edlptheme/assets/scripts/main.js | 27 ++++++++++--------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/sites/all/modules/figli/edlp_studio/assets/js/edlp_studio.js b/sites/all/modules/figli/edlp_studio/assets/js/edlp_studio.js index 326dcf7bc..5b34581d1 100644 --- a/sites/all/modules/figli/edlp_studio/assets/js/edlp_studio.js +++ b/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({ diff --git a/sites/all/modules/figli/edlp_studio/includes/edlp_composition_ui.inc b/sites/all/modules/figli/edlp_studio/includes/edlp_composition_ui.inc index 2d326001f..b02ead17b 100644 --- a/sites/all/modules/figli/edlp_studio/includes/edlp_composition_ui.inc +++ b/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; + } } diff --git a/sites/all/modules/figli/edlp_studio/src/Controller/StudioUIController.php b/sites/all/modules/figli/edlp_studio/src/Controller/StudioUIController.php index f2ed8f3fd..de021de0b 100644 --- a/sites/all/modules/figli/edlp_studio/src/Controller/StudioUIController.php +++ b/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; } diff --git a/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js b/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js index 82f0e350f..65404103f 100644 --- a/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js +++ b/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 = $('
').addClass('previous') + .on('click', this.prev.bind(this)) + .appendTo(this.$controls); + this.$playpause = $('
').addClass('play-pause') + .on('click', this.togglePlayPause.bind(this)) + .appendTo(this.$controls); + this.$next = $('
').addClass('next') + .on('click', this.next.bind(this)) + .appendTo(this.$controls); - this.$previous = $('
').addClass('previous') - .on('click', this.prev.bind(this)) - .appendTo(this.$controls); - this.$playpause = $('
').addClass('play-pause') - .on('click', this.togglePlayPause.bind(this)) - .appendTo(this.$controls); - this.$next = $('
').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(){ diff --git a/sites/all/themes/custom/edlptheme/assets/scripts/main.js b/sites/all/themes/custom/edlptheme/assets/scripts/main.js index 82f0e350f..65404103f 100644 --- a/sites/all/themes/custom/edlptheme/assets/scripts/main.js +++ b/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 = $('
').addClass('previous') + .on('click', this.prev.bind(this)) + .appendTo(this.$controls); + this.$playpause = $('
').addClass('play-pause') + .on('click', this.togglePlayPause.bind(this)) + .appendTo(this.$controls); + this.$next = $('
').addClass('next') + .on('click', this.next.bind(this)) + .appendTo(this.$controls); - this.$previous = $('
').addClass('previous') - .on('click', this.prev.bind(this)) - .appendTo(this.$controls); - this.$playpause = $('
').addClass('play-pause') - .on('click', this.togglePlayPause.bind(this)) - .appendTo(this.$controls); - this.$next = $('
').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(){