forked from grohman/OctoTattler
/
Plugin.php
76 lines (65 loc) · 2.39 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
<?php namespace Grohman\Tattler;
use Backend\Facades\BackendAuth;
use Event;
use Grohman\Tattler\Facades\Tattler;
use System\Classes\PluginBase;
/**
* tattler Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'tattler',
'description' => 'No description provided yet...',
'author' => 'Grohman',
'icon' => 'icon-leaf'
];
}
public function boot()
{
if (null != config()->get('grohman.tattler::server')) {
Event::listen('backend.list.extendColumns', function ($widget) {
$this->inject($widget);
});
Event::listen('backend.form.extendFields', function ($widget) {
$this->inject($widget);
});
}
}
protected function inject($widget)
{
if (isset($widget->model) && method_exists($widget->model, 'isClassExtendedWith')) {
if ($widget->model->isClassExtendedWith('\Grohman\Tattler\Lib\Inject') == false) {
$widget->model->extendClassWith('\Grohman\Tattler\Lib\Inject');
}
if (method_exists($widget, 'getColumns')) {
$columns = $widget->model->getWidgetColumns($widget->getColumns());
} else {
$columns = $widget->model->getWidgetColumns();
}
if ($columns) {
$room = Tattler::addRoom(get_class($widget->model));
$room->allow();
$user = Tattler::addUser(BackendAuth::getUser());
$user->allow();
$this->loadAssets($widget, Tattler::getDefaultRooms([ $room->getName(), $user->getName() ]));
}
}
}
protected function loadAssets($widget, $rooms)
{
$widget->addCss('https://cdn.jsdelivr.net/jquery.gritter/1.7.4/css/jquery.gritter.css');
$widget->addJs('https://cdn.jsdelivr.net/jquery.gritter/1.7.4/js/jquery.gritter.min.js');
$widget->addJs('https://cdn.socket.io/socket.io-1.3.7.js');
$widget->addJs('/plugins/grohman/tattler/js/tattler.js',
[ 'id' => 'tattlerJs', 'data-debug' => env('APP_DEBUG'), 'data-rooms' => json_encode($rooms) ]);
$widget->addJs('/plugins/grohman/tattler/js/crud_handlers.js');
}
}