@@ -52,7 +52,7 @@ public function __construct()
52
52
{
53
53
$ this ->name = 'ps_imageslider ' ;
54
54
$ this ->tab = 'front_office_features ' ;
55
- $ this ->version = '3.1.4 ' ;
55
+ $ this ->version = '3.2.0 ' ;
56
56
$ this ->author = 'PrestaShop ' ;
57
57
$ this ->need_instance = 0 ;
58
58
$ this ->secure_key = Tools::hash ($ this ->name );
@@ -62,7 +62,7 @@ public function __construct()
62
62
63
63
$ this ->displayName = $ this ->trans ('Image slider ' , [], 'Modules.Imageslider.Admin ' );
64
64
$ this ->description = $ this ->trans ('Add sliding images to your homepage to welcome your visitors in a visual and friendly way. ' , [], 'Modules.Imageslider.Admin ' );
65
- $ this ->ps_versions_compliancy = ['min ' => '1.7.4 .0 ' , 'max ' => _PS_VERSION_ ];
65
+ $ this ->ps_versions_compliancy = ['min ' => '1.7.5 .0 ' , 'max ' => _PS_VERSION_ ];
66
66
67
67
$ this ->templateFile = 'module:ps_imageslider/views/templates/hook/slider.tpl ' ;
68
68
}
@@ -75,6 +75,7 @@ public function install()
75
75
/* Adds Module */
76
76
if (
77
77
parent ::install () &&
78
+ $ this ->installTab () &&
78
79
$ this ->registerHook ('displayHeader ' ) &&
79
80
$ this ->registerHook ('displayHome ' ) &&
80
81
$ this ->registerHook ('actionShopDataDuplication ' )
@@ -125,6 +126,21 @@ public function install()
125
126
return false ;
126
127
}
127
128
129
+ public function installTab ()
130
+ {
131
+ $ tab = new Tab ();
132
+ $ tab ->class_name = 'AdminConfigureSlides ' ;
133
+ $ tab ->module = $ this ->name ;
134
+ $ tab ->active = true ;
135
+ $ tab ->id_parent = -1 ;
136
+ $ tab ->name = array_fill_keys (
137
+ Language::getIDs (false ),
138
+ $ this ->displayName
139
+ );
140
+
141
+ return $ tab ->add ();
142
+ }
143
+
128
144
/**
129
145
* Adds samples
130
146
*/
@@ -158,6 +174,9 @@ public function uninstall()
158
174
/* Deletes tables */
159
175
$ res = $ this ->deleteTables ();
160
176
177
+ /* Delete hidden tab */
178
+ $ res &= $ this ->uninstallTab ();
179
+
161
180
/* Unsets configuration */
162
181
$ res &= Configuration::deleteByName ('HOMESLIDER_SPEED ' );
163
182
$ res &= Configuration::deleteByName ('HOMESLIDER_PAUSE_ON_HOVER ' );
@@ -169,6 +188,18 @@ public function uninstall()
169
188
return false ;
170
189
}
171
190
191
+ public function uninstallTab ()
192
+ {
193
+ $ result = true ;
194
+ $ id_tab = (int ) Tab::getIdFromClassName ('AdminConfigureSlides ' );
195
+ $ tab = new Tab ($ id_tab );
196
+ if (Validate::isLoadedObject ($ tab )) {
197
+ $ result = $ tab ->delete ();
198
+ }
199
+
200
+ return $ result ;
201
+ }
202
+
172
203
/**
173
204
* Creates tables
174
205
*/
@@ -613,31 +644,52 @@ public function hookActionShopDataDuplication($params)
613
644
614
645
public function headerHTML ()
615
646
{
616
- if ('AdminModules ' !== Tools::getValue ('controller ' ) ||
617
- Tools::getValue ('configure ' ) !== $ this ->name ||
618
- Tools::getIsset ('id_slide ' ) ||
619
- Tools::getIsset ('addSlide ' )) {
647
+ // Run only on module configuration page
648
+ if (Tools::getValue ('controller ' ) != 'AdminModules ' || Tools::getValue ('configure ' ) !== $ this ->name ) {
620
649
return ;
621
650
}
622
651
623
- $ this ->context ->controller ->addJS ($ this ->_path . 'js/Sortable.min.js ' );
624
- /* Style & js for fieldset 'slides configuration' */
625
- $ html = '<script type="text/javascript">
626
- $(function() {
627
- var $mySlides = $("#slides");
628
- new Sortable($mySlides[0], {
629
- animation: 150,
630
- onUpdate: function(event) {
631
- var order = this.toArray().join("&") + "&action=updateSlidesPosition";
632
- $.post(" ' . $ this ->context ->shop ->physical_uri . $ this ->context ->shop ->virtual_uri . 'modules/ ' . $ this ->name . '/ajax_ ' . $ this ->name . '.php?secure_key= ' . $ this ->secure_key . '", order);
633
- }
634
- });
635
- $mySlides.hover(function() {
636
- $(this).css("cursor","move");
637
- },
638
- function() {
639
- $(this).css("cursor","auto");
652
+ // Add sortable library
653
+ $ this ->context ->controller ->addJS ($ this ->_path . 'js/Sortable.min.js?v= ' . $ this ->version );
654
+
655
+ // Add sorting scripts
656
+ $ html = '
657
+ <script type="text/javascript">
658
+ $(function () {
659
+ var slideList = $("#slides");
660
+
661
+ // Check if the list exists, so we dont run it on edit page
662
+ if (!slideList.length) {
663
+ return;
664
+ }
665
+
666
+ new Sortable(slideList[0], {
667
+ animation: 150,
668
+ onUpdate: function (event) {
669
+ var sortableIdsAsTableString = this.toArray();
670
+ var sortableIdsAsData = sortableIdsAsTableString.map((x) => x.slice(-1));
671
+ var ajaxCallParameters = {
672
+ ajax: true,
673
+ action: "updateSlidesPosition",
674
+ slides: sortableIdsAsData
675
+ };
676
+ $.ajax({
677
+ type: "POST",
678
+ cache: false,
679
+ url: " ' . $ this ->context ->link ->getAdminLink ('AdminConfigureSlides ' ) . '",
680
+ data: ajaxCallParameters
681
+ });
682
+ }
640
683
});
684
+
685
+ slideList.hover(
686
+ function () {
687
+ $(this).css("cursor", "move");
688
+ },
689
+ function () {
690
+ $(this).css("cursor", "auto");
691
+ }
692
+ );
641
693
});
642
694
</script> ' ;
643
695
0 commit comments