This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlugin.php
113 lines (97 loc) · 3.41 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php namespace Initbiz\PowerComponents;
use Lang;
use Event;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
use \System\Traits\EventEmitter;
public function register()
{
$this->registerConsoleCommand('pc.crud', 'Initbiz\PowerComponents\Console\PcUtil');
}
public function registerFormWidgets()
{
return [
'Initbiz\PowerComponents\FormWidgets\DynamicForm' => 'dynamicform',
];
}
public function registerFrontendFormWidgets()
{
return [
'Initbiz\PowerComponents\FrontendFormWidgets\Relation' => 'relation',
'Initbiz\PowerComponents\FrontendFormWidgets\Repeater' => 'repeater',
'Initbiz\PowerComponents\FrontendFormWidgets\DatePicker' => 'datepicker',
// 'Initbiz\PowerComponents\FrontendFormWidgets\CodeEditor' => 'codeeditor',
'Initbiz\PowerComponents\FrontendFormWidgets\FileUpload' => 'fileupload',
'Initbiz\PowerComponents\FrontendFormWidgets\TagList' => 'taglist',
'Initbiz\PowerComponents\FrontendFormWidgets\ColorPicker' => 'colorpicker',
'Initbiz\PowerComponents\FrontendFormWidgets\DynamicForm' => 'dynamicform',
'Initbiz\PowerComponents\FrontendFormWidgets\RichEditor' => 'richeditor',
];
}
public function registerMarkupTags()
{
return [
'functions' => [
'pcrender' => [$this, 'pcrender']
]
];
}
/**
* Render part
* @param string $widgetName to be rendered
* @param array $options array containing options of a component
* @return string
*/
public function pcrender($widgetName, $options)
{
$ajaxHandlerName = '';
$widgetsWithHandlers = [
'list' => 'onRefreshList',
'form' => 'onRefreshForm',
];
$this->fireEvent('pc.handlers.beforePcrender', [$widgetsWithHandlers], false);
foreach ($widgetsWithHandlers as $name => $handler) {
if ($widgetName === $name) {
$ajaxHandlerName = $handler;
break;
}
}
if ($ajaxHandlerName === '') {
return 'Unknown widget type';
}
$divId = 'pc-'.$widgetName.'-'.$options['componentAlias'];
return '
<div id="'.$divId.'" class="empowered-component">
'.$this->preloaderContent().'
</div>
<script>
$(document).ready(function() {
$.request(\''.$options['componentAlias'].'::'.$ajaxHandlerName.'\', {
data: '.json_encode($options).'
});
});
</script>
';
}
/**
* Method returning preloader div content. It will be replaced after successfull AJAX
* @return string $content to be placed in components div
*/
public function preloaderContent()
{
//TODO: move this one to view file which can be overriden theme wide
$content = '
<div class="loading-indicator-container">
<div class="loading-indicator indicator-center">
<span></span>
<div>'.
Lang::get('initbiz.powercomponents::lang.misc.loader_text')
.'</div>
</div>
</div>
';
Event::fire('pc.frontend.preloader.beforeRender', [&$content]);
return $content;
}
}