Passed
Push — develop ( 616438...84d7aa )
by Nikolay
06:16 queued 11s
created

AssetProvider::makeUpdateAssets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 16
rs 9.8333
cc 2
nc 2
nop 1
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
declare(strict_types=1);
21
22
namespace MikoPBX\AdminCabinet\Providers;
23
24
use Phalcon\Assets\Collection;
25
use MikoPBX\AdminCabinet\Plugins\AssetManager as Manager;
26
use Phalcon\Di\DiInterface;
27
use Phalcon\Di\ServiceProviderInterface;
28
29
use function MikoPBX\Common\Config\appPath;
30
31
class AssetProvider implements ServiceProviderInterface
32
{
33
    public const SERVICE_NAME = 'assets';
34
35
    private Collection $headerCollectionJSForExtensions;
36
    private Collection $footerCollectionJSForExtensions;
37
    private Collection $headerCollectionJS;
38
    private Collection $headerCollectionCSS;
39
    private Collection $footerCollectionJS;
40
    private Collection $semanticCollectionCSS;
41
    private Collection $semanticCollectionJS;
42
    private Collection $footerCollectionACE;
43
    private Collection $footerCollectionLoc;
44
    private Collection $headerCollectionSentryJS;
45
    private string $cssCacheDir;
46
    private string $jsCacheDir;
47
    private Manager $manager;
48
49
    /**
50
     * Registers assets service provider
51
     *
52
     * @param \Phalcon\Di\DiInterface $di
53
     */
54
    public function register(DiInterface $di): void
55
    {
56
        $di->set(
57
            self::SERVICE_NAME,
58
            function () use ($di) {
59
                $session    = $di->get('session');
60
                if ($session !== null && $session->has('versionHash')) {
61
                    $version = (string)$session->get('versionHash');
62
                } else {
63
                    $version = str_replace(PHP_EOL, '', file_get_contents('/etc/version'));
64
                }
65
66
                $assets = new AssetProvider();
67
                $assets->initializeClassVariables($version);
68
                $dispatcher = $di->get('dispatcher');
69
                $controller = $dispatcher->getControllerName();
70
                $action     = $dispatcher->getActionName();
71
                $moduleName = $dispatcher->getModuleName();
72
73
                if ($action === null) {
74
                    $action = 'index';
75
                }
76
77
                $assets->makeSentryAssets();
78
                $assets->makeHeaderAssets($session, $moduleName);
79
80
                // Generates Controllers assets
81
                $method_name = "make{$controller}Assets";
82
                if (method_exists($assets, $method_name)) {
83
                    $assets->$method_name($action);
84
                }
85
86
                $assets->makeFooterAssets();
87
                $assets->makeLocalizationAssets($di, $version);
88
89
                return $assets->manager;
90
            }
91
        );
92
    }
93
94
    /**
95
     * Initialize class variables
96
     */
97
    public function initializeClassVariables(string $version)
98
    {
99
        $this->manager = new Manager();
100
        $this->manager->setVersion($version);
101
102
        $this->cssCacheDir = appPath('sites/admin-cabinet/assets/css/cache');
103
        $this->jsCacheDir  = appPath('sites/admin-cabinet/assets/js/cache');
104
105
        $this->headerCollectionJSForExtensions = $this->manager->collection('headerJS');
106
        $this->headerCollectionJSForExtensions->setPrefix('assets/');
107
        $this->footerCollectionJSForExtensions = $this->manager->collection('footerJS');
108
        $this->footerCollectionJSForExtensions->setPrefix('assets/');
109
        $this->headerCollectionJS = $this->manager->collection('headerPBXJS');
110
        $this->headerCollectionJS->setPrefix('assets/');
111
        $this->headerCollectionCSS = $this->manager->collection('headerCSS');
112
        $this->headerCollectionCSS->setPrefix('assets/');
113
        $this->footerCollectionJS = $this->manager->collection('footerPBXJS');
114
        $this->footerCollectionJS->setPrefix('assets/');
115
        $this->headerCollectionSentryJS = $this->manager->collection('headerSentryJS');
116
        $this->semanticCollectionCSS    = $this->manager->collection('SemanticUICSS');
117
        $this->semanticCollectionCSS->setPrefix('assets/');
118
        $this->semanticCollectionJS = $this->manager->collection('SemanticUIJS');
119
        $this->semanticCollectionJS->setPrefix('assets/');
120
        $this->footerCollectionACE = $this->manager->collection('footerACE');
121
        $this->footerCollectionACE->setPrefix('assets/');
122
        $this->footerCollectionLoc = $this->manager->collection('footerLoc');
123
        $this->footerCollectionLoc->setPrefix('assets/');
124
    }
125
126
    /**
127
     * Makes assets for the Sentry error logger
128
     *
129
     */
130
    private function makeSentryAssets(): void
131
    {
132
        if (file_exists('/tmp/sendmetrics')) {
133
            $this->headerCollectionSentryJS->addjs(
134
                'assets/js/vendor/sentry/bundle.min.js',
135
                true
136
            );
137
            $this->headerCollectionSentryJS->addJs(
138
                "assets/js/pbx/main/sentry-error-logger.js",
139
                true
140
            );
141
        }
142
    }
143
144
    /**
145
     * Makes assets for all controllers. Base set of scripts and styles
146
     *
147
     * @param $session
148
     * @param $moduleName
149
     */
150
    private function makeHeaderAssets($session, $moduleName): void
151
    {
152
        $this->semanticCollectionCSS
153
            ->addCss('css/vendor/semantic/grid.min.css', true)
154
            ->addCss('css/vendor/semantic/divider.min.css', true)
155
            ->addCss('css/vendor/semantic/container.min.css', true)
156
            ->addCss('css/vendor/semantic/header.min.css', true)
157
            ->addCss('css/vendor/semantic/button.min.css', true)
158
            ->addCss('css/vendor/semantic/form.min.css', true)
159
            ->addCss('css/vendor/semantic/icon.min.css', true)
160
            ->addCss('css/vendor/semantic/flag.min.css', true)
161
            ->addCss('css/vendor/semantic/image.min.css', true)
162
            ->addCss('css/vendor/semantic/input.min.css', true)
163
            ->addCss('css/vendor/semantic/message.min.css', true)
164
            ->addCss('css/vendor/semantic/segment.min.css', true)
165
            ->addCss('css/vendor/semantic/site.min.css', true)
166
            ->addCss('css/vendor/semantic/reset.min.css', true)
167
            ->addCss('css/vendor/semantic/transition.min.css', true)
168
            ->addCss('css/vendor/semantic/dropdown.min.css', true)
169
            ->addCss('css/vendor/semantic/checkbox.min.css', true);
170
171
        $this->headerCollectionJS
172
            ->addJs('js/pbx/main/header.js', true)
173
            ->addJs('js/vendor/jquery.min.js', true);
174
175
        $this->footerCollectionJS
176
            ->addJs('js/pbx/main/language-select.js', true);
177
178
        $this->semanticCollectionJS
179
            ->addJs('js/vendor/semantic/form.min.js', true)
180
            ->addJs('js/vendor/semantic/api.min.js', true)
181
            ->addJs('js/vendor/semantic/site.min.js', true)
182
            ->addJs('js/vendor/semantic/popup.min.js', true)
183
            ->addJs('js/vendor/semantic/dropdown.min.js', true)
184
            ->addJs('js/vendor/semantic/transition.min.js', true)
185
            ->addJs('js/vendor/semantic/checkbox.min.js', true);
186
187
        // Если пользователь залогинился, сформируем необходимые CSS кеши
188
        if ($session && $session->has('auth')) {
189
            $this->semanticCollectionCSS
190
                ->addCss('css/vendor/semantic/menu.min.css', true)
191
                ->addCss('css/vendor/semantic/sidebar.min.css', true)
192
                ->addCss('css/vendor/semantic/table.min.css', true)
193
                ->addCss('css/vendor/semantic/loader.min.css', true)
194
                ->addCss('css/vendor/semantic/label.min.css', true)
195
                ->addCss('css/vendor/semantic/dimmer.min.css', true)
196
                ->addCss('css/vendor/semantic/accordion.min.css', true)
197
                ->addCss('css/vendor/semantic/placeholder.min.css', true)
198
                ->addCss('css/vendor/semantic/item.min.css', true)
199
                ->addCss('css/vendor/semantic/tab.min.css', true)
200
                ->addCss('css/vendor/semantic/popup.min.css', true)
201
                ->addCss('css/vendor/semantic/toast.min.css', true);
202
203
            $this->semanticCollectionJS
204
                ->addJs('js/vendor/semantic/accordion.min.js', true)
205
                ->addJs('js/vendor/semantic/dimmer.min.js', true)
206
                ->addJs('js/vendor/semantic/sidebar.min.js', true)
207
                ->addJs('js/vendor/semantic/toast.min.js', true)
208
                ->addJs('js/vendor/semantic/tab.min.js', true);
209
210
            $this->footerCollectionJS
211
                ->addJs(
212
                    'js/pbx/main/config.js',
213
                    true
214
                )
215
                ->addJs(
216
                    'js/pbx/main/pbxapi.js',
217
                    true
218
                )
219
                ->addJs(
220
                    'js/pbx/main/connection-check-worker.js',
221
                    true
222
                )
223
                ->addJs(
224
                    'js/pbx/main/semantic-localization.js',
225
                    true
226
                )
227
                ->addJs(
228
                    'js/pbx/Advices/advices-worker.js',
229
                    true
230
                )
231
                ->addJs(
232
                    'js/pbx/SendMetrics/send-metrics-index.js',
233
                    true
234
                )
235
                ->addJs(
236
                    'js/pbx/main/ssh-console.js',
237
                    true
238
                )
239
                ->addJs(
240
                    'js/pbx/main/delete-something.js',
241
                    true
242
                )
243
                ->addJs(
244
                    'js/pbx/main/user-message.js',
245
                    true
246
                )
247
                ->addJs(
248
                    'js/pbx/Extensions/extensions.js',
249
                    true
250
                )
251
                ->addJs(
252
                    'js/pbx/PbxExtensionModules/pbx-extension-menu-addition.js',
253
                    true
254
                )
255
                ->addJs(
256
                    'js/pbx/TopMenuSearch/top-menu-search.js',
257
                    true
258
                );
259
260
            if ($moduleName === 'PBXExtension') {
261
                $this->footerCollectionJS->addJs(
262
                    'js/pbx/PbxExtensionModules/pbx-extension-module-status.js',
263
                    true
264
                );
265
            }
266
        }
267
    }
268
269
    /**
270
     * Makes footer assets
271
     */
272
    private function makeFooterAssets(): void
273
    {
274
        $this->headerCollectionCSS
275
            ->addCss('css/custom.css', true);
276
277
        $this->footerCollectionJS->addJs(
278
            'js/pbx/main/footer.js',
279
            true
280
        );
281
    }
282
283
    /**
284
     * Makes Language cache for browser JS scripts
285
     *
286
     * @param \Phalcon\Di\DiInterface $di
287
     * @param string                  $version
288
     */
289
    private function makeLocalizationAssets(DiInterface $di, string $version): void
290
    {
291
        $language   = $di->getShared('language');
292
        $fileName    = "{$this->jsCacheDir}/localization-{$language}-{$version}.min.js";
293
        if ( ! file_exists($fileName)) {
294
            $arrStr = [];
295
            foreach ($di->getShared('messages') as $key => $value) {
296
                $arrStr[$key] = str_replace(
297
                    "'",
298
                    "\\'",
299
                    str_replace(["\n", '  '], '', $value)
300
                );
301
            }
302
            $scriptArray = json_encode($arrStr);
303
            file_put_contents($fileName, "globalTranslate = {$scriptArray}");
304
        }
305
306
        $langJSFile = "js/cache/localization-{$language}-{$version}.min.js";
307
        $this->footerCollectionLoc->addJs($langJSFile, true);
308
    }
309
310
    /**
311
     * Makes assets for the CallQueues controller
312
     *
313
     * @param string $action
314
     */
315
    private function makeCallQueuesAssets(string $action)
316
    {
317
        if ($action === 'index') {
318
            $this->headerCollectionCSS
319
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
320
            $this->footerCollectionJS
321
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
322
                ->addJs('js/pbx/CallQueues/callqueues-index.js', true);
323
        } elseif ($action === 'modify') {
324
            $this->footerCollectionJS
325
                ->addJs('js/vendor/jquery.debounce-1.0.5.js', true)
326
                ->addJs('js/vendor/jquery.tablednd.js', true)
327
                ->addJs('js/pbx/main/form.js', true)
328
                ->addJs('js/pbx/CallQueues/callqueue-modify.js', true)
329
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
330
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
331
        }
332
    }
333
334
    /**
335
     * Makes assets for the ConferenceRooms controller
336
     *
337
     * @param string $action
338
     */
339
    private function makeConferenceRoomsAssets(string $action)
340
    {
341
        if ($action === 'index') {
342
            $this->footerCollectionJS
343
                ->addJs('js/pbx/ConferenceRooms/conference-rooms-index.js', true);
344
        } elseif ($action === 'modify') {
345
            $this->footerCollectionJS
346
                ->addJs('js/pbx/main/form.js', true)
347
                ->addJs('js/pbx/ConferenceRooms/conference-room-modify.js', true);
348
        }
349
    }
350
351
    /**
352
     * Makes assets for the SystemDiagnostic controller
353
     *
354
     * @param string $action
355
     */
356
    private function makeSystemDiagnosticAssets(string $action): void
357
    {
358
        if ($action === 'index') {
359
            $this->footerCollectionJS
360
                ->addJs('js/vendor/semantic/popup.min.js', true)
361
                ->addJs('js/vendor/semantic/dropdown.min.js', true)
362
                ->addJs('js/pbx/main/form.js', true)
363
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index.js', true)
364
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-showlogs.js', true)
365
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-sysinfo.js', true)
366
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-logcapture.js', true);
367
            $this->footerCollectionACE
368
                ->addJs('js/vendor/ace/ace.js', true)
369
                ->addJs('js/vendor/ace/mode-julia.js', true);
370
        }
371
    }
372
373
    /**
374
     * Makes assets for the SoundFiles controller
375
     *
376
     * @param string $action
377
     */
378
    private function makeSoundFilesAssets(string $action): void
379
    {
380
        if ($action === 'index') {
381
            $this->headerCollectionCSS
382
                ->addCss('css/vendor/range/range.css')
383
                ->addCss(
384
                    'css/vendor/datatable/dataTables.semanticui.css',
385
                    true
386
                );
387
            $this->footerCollectionJS->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
388
                ->addJs('js/vendor/range/range.min.js', true)
389
                ->addJs('js/vendor/jquery.address.min.js', true)
390
                ->addJs('js/pbx/SoundFiles/sound-files-index-player.js', true)
391
                ->addJs('js/pbx/SoundFiles/sound-files-index.js', true);
392
        } elseif ($action === 'modify') {
393
            $this->headerCollectionCSS->addCss('css/vendor/range/range.css');
394
395
            $this->headerCollectionJS
396
                ->addJs(
397
                    'js/vendor/webrtc/MediaStreamRecorder.min.js',
398
                    true
399
                )
400
                ->addJs('js/vendor/webrtc/adapter-latest.min.js', true);
401
402
            $this->footerCollectionJS
403
                ->addJs('js/vendor/range/range.min.js', true)
404
                ->addJs('js/pbx/main/form.js', true)
405
                ->addJs('js/vendor/resumable.js', true)
406
                ->addJs('js/pbx/SoundFiles/sound-file-modify-player.js', true)
407
                ->addJs('js/pbx/SoundFiles/sound-file-modify-upload-worker.js', true)
408
                ->addJs('js/pbx/SoundFiles/sound-file-modify-webkit-recorder.js', true)
409
                ->addJs('js/pbx/SoundFiles/sound-file-modify.js', true);
410
        }
411
    }
412
413
    /**
414
     * Makes assets for the TimeSettings controller
415
     *
416
     * @param string $action
417
     */
418
    private function makeTimeSettingsAssets(string $action): void
419
    {
420
        if ($action === 'modify') {
421
            $this->footerCollectionJS
422
                ->addJs('js/pbx/main/form.js', true)
423
                ->addJs('js/vendor/moment/moment-with-locales.min.js',true)
424
                ->addJs('js/vendor/moment/moment-timezone-with-data.js', true)
425
                ->addJs('js/pbx/TimeSettings/time-settings-worker.js', true)
426
                ->addJs('js/pbx/TimeSettings/time-settings-modify.js', true);
427
        }
428
    }
429
430
    /**
431
     * Makes assets for the Update controller
432
     *
433
     * @param string $action
434
     */
435
    private function makeUpdateAssets(string $action): void
436
    {
437
        if ($action === 'index') {
438
            $this->footerCollectionJS
439
                ->addJs('js/pbx/main/version-compare.js', true)
440
                ->addJs('js/pbx/main/form.js', true)
441
                ->addJs('js/vendor/resumable.js', true)
442
                ->addJs('js/vendor/showdown/showdown.min.js', true)
443
                ->addJs('js/pbx/Update/update-index.js', true);
444
            $this->semanticCollectionCSS
445
                ->addCss('css/vendor/semantic/progress.min.css', true)
446
                ->addCss('css/vendor/semantic/modal.min.css', true);
447
448
            $this->semanticCollectionJS
449
                ->addJs('js/vendor/semantic/progress.min.js', true)
450
                ->addJs('js/vendor/semantic/modal.min.js', true);
451
        }
452
    }
453
454
    /**
455
     * Makes assets for the Session controller
456
     *
457
     * @param string $action
458
     */
459
    private function makeSessionAssets(string $action): void
460
    {
461
        if ($action === 'index') {
462
            $this->footerCollectionJS
463
                ->addJs('js/pbx/main/form.js', true)
464
                ->addJs('js/pbx/Session/login-form.js', true);
465
        }
466
    }
467
468
    /**
469
     * Makes assets for the Restart controller
470
     *
471
     * @param string $action
472
     */
473
    private function makeRestartAssets(string $action): void
474
    {
475
        if ($action === 'index') {
476
            $this->footerCollectionJS
477
                ->addJs('js/pbx/Restart/restart-index.js', true);
478
        }
479
    }
480
481
    /**
482
     * Makes assets for the Providers controller
483
     *
484
     * @param string $action
485
     */
486
    private function makeProvidersAssets(string $action): void
487
    {
488
        if ($action === 'index') {
489
            $this->semanticCollectionCSS
490
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true)
491
                ->addCss('css/vendor/semantic/modal.min.css', true);
492
493
            $this->semanticCollectionJS
494
                ->addJs('js/vendor/semantic/modal.min.js', true);
495
            $this->footerCollectionJS
496
                ->addJs('js/pbx/main/debugger-info.js', true)
497
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
498
                ->addJs('js/pbx/Providers/providers-index.js', true);
499
        } elseif ($action === 'modifysip' || $action === 'modifyiax') {
500
            $this->footerCollectionJS
501
                ->addJs('js/pbx/main/form.js', true)
502
                ->addJs('js/pbx/main/debugger-info.js', true)
503
                ->addJs('js/pbx/Providers/provider-modify-status-worker.js', true)
504
                ->addJs('js/pbx/Providers/provider-modify.js', true);
505
        }
506
    }
507
508
    /**
509
     *  Makes assets for the PbxExtensionModules controller
510
     *
511
     * @param string $action
512
     */
513
    private function makePbxExtensionModulesAssets(string $action): void
514
    {
515
        if ($action === 'index') {
516
            $this->semanticCollectionJS->addJs('js/vendor/semantic/modal.min.js', true);
517
            $this->footerCollectionJS
518
                ->addJs('js/pbx/Update/update-api.js', true)
519
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
520
                ->addJs('js/vendor/resumable.js', true)
521
                ->addJs(
522
                    'js/pbx/PbxExtensionModules/pbx-extension-module-upgrade-status-worker.js',
523
                    true
524
                )
525
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-status.js', true)
526
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-modules-index.js', true)
527
                ->addJs('js/vendor/semantic/progress.min.js', true)
528
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-add-new.js', true);
529
            $this->semanticCollectionCSS
530
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true)
531
                ->addCss('css/vendor/semantic/modal.min.css', true)
532
                ->addCss('css/vendor/semantic/progress.min.css', true);
533
        } elseif ($action === 'modify') {
534
            $this->footerCollectionJS
535
                ->addJs('js/pbx/main/form.js', true)
536
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-modify.js', true);
537
        }
538
    }
539
540
    /**
541
     * Makes assets for the OutOffWorkTime controller
542
     *
543
     * @param string $action
544
     */
545
    private function makeOutOffWorkTimeAssets(string $action): void
546
    {
547
        if ($action === 'index') {
548
            $this->footerCollectionJS
549
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-times-index.js', true);
550
        } elseif ($action === 'modify') {
551
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/calendar.min.css', true);
552
            $this->semanticCollectionJS->addJs('js/vendor/semantic/calendar.min.js', true);
553
            $this->footerCollectionJS
554
                ->addJs('js/pbx/main/form.js', true)
555
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-time-modify.js', true)
556
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
557
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
558
        }
559
    }
560
561
    /**
562
     * Makes assets for the OutboundRoutes controller
563
     *
564
     * @param string $action
565
     */
566
    private function makeOutboundRoutesAssets(string $action): void
567
    {
568
        if ($action === 'index') {
569
            $this->footerCollectionJS
570
                ->addJs('js/vendor/jquery.tablednd.min.js', true)
571
                ->addJs('js/pbx/OutboundRoutes/outbound-routes-index.js', true);
572
        } elseif ($action === 'modify') {
573
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
574
                ->addJs('js/pbx/OutboundRoutes/outbound-route-modify.js', true);
575
        }
576
    }
577
578
    /**
579
     * Makes assets for the Network controller
580
     *
581
     * @param string $action
582
     */
583
    private function makeNetworkAssets(string $action): void
584
    {
585
        if ($action === 'modify') {
586
            $this->footerCollectionJS
587
                ->addJs('js/vendor/inputmask/inputmask.js', true)
588
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
589
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
590
                ->addJs('js/vendor/inputmask/init.js', true)
591
                ->addJs('js/pbx/main/form.js', true)
592
                ->addJs('js/pbx/Network/network-modify.js', true);
593
        }
594
    }
595
596
    /**
597
     * Makes assets for the MailSettings controller
598
     *
599
     * @param string $action
600
     */
601
    private function makeMailSettingsAssets(string $action): void
602
    {
603
        if ($action === 'modify') {
604
            $this->footerCollectionJS
605
                ->addJs('js/pbx/main/form.js', true)
606
                ->addJs('js/pbx/MailSettings/mail-settings-modify.js', true);
607
        }
608
    }
609
610
    /**
611
     * Makes assets for the Licensing controller
612
     *
613
     * @param string $action
614
     */
615
    private function makeLicensingAssets(string $action): void
616
    {
617
        if ($action === 'modify') {
618
            $this->footerCollectionJS
619
                ->addJs('js/vendor/inputmask/inputmask.js', true)
620
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
621
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
622
                ->addJs('js/vendor/inputmask/init.js', true)
623
                ->addJs('js/pbx/main/form.js', true)
624
                ->addJs('js/pbx/Licensing/licensing-modify.js', true);
625
        }
626
    }
627
628
    /**
629
     * Makes assets for the IvrMenu controller
630
     *
631
     * @param string $action
632
     */
633
    private function makeIvrMenuAssets(string $action): void
634
    {
635
        if ($action === 'index') {
636
            $this->headerCollectionCSS
637
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
638
            $this->footerCollectionJS
639
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
640
                ->addJs('js/pbx/IvrMenu/ivrmenu-index.js', true);
641
        } elseif ($action === 'modify') {
642
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
643
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
644
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
645
                ->addJs('js/pbx/IvrMenu/ivrmenu-modify.js', true);
646
        }
647
    }
648
649
    /**
650
     * Makes assets for the IncomingRoutes controller
651
     *
652
     * @param string $action
653
     */
654
    private function makeIncomingRoutesAssets(string $action): void
655
    {
656
        if ($action === 'index') {
657
            $this->footerCollectionJS->addJs('js/vendor/jquery.tablednd.js', true)
658
                ->addJs('js/pbx/main/form.js', true)
659
                ->addJs('js/pbx/IncomingRoutes/incoming-route-index.js', true);
660
        } elseif ($action === 'modify') {
661
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
662
                ->addJs('js/pbx/IncomingRoutes/incoming-route-modify.js', true);
663
        }
664
    }
665
666
    /**
667
     * Makes assets for the GeneralSettings controller
668
     *
669
     * @param string $action
670
     */
671
    private function makeGeneralSettingsAssets(string $action): void
672
    {
673
        if ($action === 'modify') {
674
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/progress.min.css', true);
675
            $this->semanticCollectionJS->addJs('js/vendor/semantic/progress.min.js', true);
676
            $this->footerCollectionJS
677
                ->addJs('js/vendor/jquery.address.min.js', true)
678
                ->addJs('js/vendor/jquery.tablednd.js', true)
679
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
680
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
681
                ->addJs('js/pbx/main/form.js', true)
682
                ->addJs('js/pbx/main/password-score.js', true)
683
                ->addJs(
684
                    'js/pbx/GeneralSettings/general-settings-modify.js',
685
                    true
686
                );
687
        }
688
    }
689
690
    /**
691
     * Makes assets for the Firewall controller
692
     *
693
     * @param string $action
694
     */
695
    private function makeFirewallAssets(string $action): void
696
    {
697
        if ($action === 'index') {
698
            $this->footerCollectionJS
699
                ->addJs('js/pbx/Firewall/firewall-index.js', true);
700
        } elseif ($action === 'modify') {
701
            $this->footerCollectionJS
702
                ->addJs('js/pbx/main/form.js', true)
703
                ->addJs('js/pbx/Firewall/firewall-modify.js', true);
704
        }
705
    }
706
707
    /**
708
     * Makes assets for the Fail2Ban controller
709
     *
710
     * @param string $action
711
     */
712
    private function makeFail2BanAssets(string $action): void
713
    {
714
        if ($action === 'index') {
715
            $this->footerCollectionJS
716
                ->addJs('js/pbx/main/form.js', true)
717
                ->addJs('js/pbx/Fail2Ban/fail-to-ban-index.js', true);
718
        }
719
    }
720
721
    /**
722
     * Makes assets for the Extensions controller
723
     *
724
     * @param string $action
725
     */
726
    private function makeExtensionsAssets(string $action): void
727
    {
728
        if ($action === 'index') {
729
            $this->headerCollectionCSS->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
730
731
            $this->footerCollectionJS
732
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
733
                ->addJs('js/vendor/inputmask/inputmask.js', true)
734
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
735
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
736
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
737
                ->addJs('js/vendor/inputmask/init.js', true)
738
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
739
                ->addJs('js/pbx/Extensions/extensions-index.js', true)
740
                ->addJs('js/pbx/main/debugger-info.js', true)
741
                ->addJs('js/vendor/clipboard/clipboard.js', true);
742
        } elseif ($action === 'modify') {
743
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/card.min.css', true);
744
            $this->footerCollectionJS
745
                ->addJs('js/vendor/inputmask/inputmask.js', true)
746
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
747
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
748
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
749
                ->addJs('js/vendor/inputmask/init.js', true)
750
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
751
                ->addJs('js/pbx/main/form.js', true)
752
                ->addJs('js/pbx/main/debugger-info.js', true)
753
                ->addJs('js/pbx/Extensions/extension-modify.js', true);
754
        }
755
    }
756
757
    /**
758
     *  Makes assets for the DialplanApplications controller
759
     *
760
     * @param string $action
761
     */
762
    private function makeDialplanApplicationsAssets(string $action): void
763
    {
764
        if ($action === 'index') {
765
            $this->headerCollectionCSS
766
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
767
            $this->footerCollectionJS
768
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
769
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-index.js', true);
770
        } elseif ($action === 'modify') {
771
            $this->footerCollectionACE
772
                ->addJs('js/vendor/ace/ace.js', true)
773
                ->addJs('js/vendor/ace/mode-php.js', true)
774
                ->addJs('js/vendor/ace/mode-julia.js', true);
775
            $this->footerCollectionJS
776
                ->addJs('js/pbx/main/form.js', true)
777
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-modify.js', true);
778
        }
779
    }
780
781
    /**
782
     * Makes assets for the CustomFiles controller
783
     *
784
     * @param string $action
785
     */
786
    private function makeCustomFilesAssets(string $action): void
787
    {
788
        if ($action === 'index') {
789
            $this->headerCollectionCSS
790
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
791
            $this->footerCollectionJS
792
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
793
                ->addJs('js/pbx/CustomFiles/custom-files-index.js', true);
794
        } elseif ($action === 'modify') {
795
            $this->footerCollectionJS
796
                ->addJs('js/pbx/main/form.js', true)
797
                ->addJs('js/pbx/CustomFiles/custom-files-modify.js', true);
798
            $this->footerCollectionACE
799
                ->addJs('js/vendor/ace/ace.js', true)
800
                ->addJs('js/vendor/ace/mode-julia.js', true);
801
        }
802
    }
803
804
    /**
805
     * Makes assets for the CallDetailRecords controller
806
     *
807
     * @param string $action
808
     */
809
    private function makeCallDetailRecordsAssets(string $action): void
810
    {
811
        if ($action === 'index') {
812
            $this->semanticCollectionJS->addJs('js/vendor/semantic/progress.min.js', true);
813
814
            $this->semanticCollectionCSS
815
                ->addCss('css/vendor/range/range.min.css', true)
816
                ->addCss('css/vendor/datatable/scroller.dataTables.min.css', true)
817
                ->addCss('css/vendor/datepicker/daterangepicker.css', true)
818
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
819
820
            $this->semanticCollectionJS
821
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
822
                ->addJs('js/vendor/datatable/dataTables.scroller.min.js', true)
823
                ->addJs('js/vendor/datatable/scroller.semanticui.js', true)
824
                //->addJs('js/vendor/datatable/dataTables.pageResize.min.js', TRUE)
825
                ->addJs('js/vendor/range/range.min.js', true)
826
                ->addJS('js/vendor/datepicker/moment.min.js', true)
827
                ->addJS('js/vendor/datepicker/daterangepicker.js', true);
828
829
            $this->footerCollectionJS
830
                ->addJs(
831
                    'js/pbx/CallDetailRecords/call-detail-records-index.js',
832
                    true
833
                );
834
        }
835
    }
836
837
    /**
838
     * Makes assets for the AsteriskManagers controller
839
     *
840
     * @param string $action
841
     */
842
    private function makeAsteriskManagersAssets(string $action): void
843
    {
844
        if ($action === 'index') {
845
            $this->footerCollectionJS->addJs('js/pbx/AsteriskManagers/managers-index.js', true);
846
        } elseif ($action === 'modify') {
847
            $this->footerCollectionJS
848
                ->addJs('js/pbx/main/form.js', true)
849
                ->addJs('js/pbx/AsteriskManagers/manager-modify.js', true);
850
        }
851
    }
852
853
854
}