Skip to content

Commit 8cc83c4

Browse files
committed
Add a Save+Back command to the section editor. Refactor.
1 parent fce3648 commit 8cc83c4

2 files changed

Lines changed: 79 additions & 40 deletions

File tree

admin-power-tools.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -99,46 +99,6 @@ public function onPluginsInitialized()
9999
// "url" => 'plugin://admin-power-tools/assets/titlebar_fix.css'
100100
// ]);
101101

102-
//
103-
// RENDERERS
104-
//
105-
106-
$manager->registerService("renderer", [
107-
"caption" => "Delete",
108-
"scope" => ["edit:section"],
109-
"order" => "last",
110-
"render" => function () {
111-
return "<a class='button' onclick='_doDelete(); return false;'><i class='fa fa-trash'></i>Delete</a>";
112-
},
113-
]);
114-
$twig = $this->grav['twig'];
115-
$manager->registerService("renderer", [
116-
"caption" => "Fullscreen",
117-
"scope" => ["edit:section"],
118-
"order" => "last",
119-
"render" => function () use ($twig) {
120-
return $twig->processTemplate("fullscreen.html.twig", ["targetSelector" => "#edit-area"]);
121-
},
122-
]);
123-
$manager->registerService("renderer", [
124-
"caption" => "Back And Refresh",
125-
"scope" => ["edit:section"],
126-
"order" => "first",
127-
"render" => function ($context) use ($twig) {
128-
// This will go back with refreshing but loose scroll position
129-
// return '<a class="button" onclick="window.location = document.referrer;"><i class="fa fa-reply"></i>Back</a>';
130-
// This will go back without refreshing but retain scroll position
131-
return '<a class="button" onclick="window.history.back()"><i class="fa fa-reply"></i>Back</a>';
132-
}
133-
]);
134-
$manager->registerService("renderer", [
135-
"caption" => "Save",
136-
"scope" => ["edit:section"],
137-
"order" => "last",
138-
"render" => function () {
139-
return "<a class='button' onclick='_doSave(); return false;'><i class='fa fa-save'></i>Save</a>";
140-
},
141-
]);
142102
}
143103
}
144104

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/*
3+
* The MIT License (MIT)
4+
*
5+
* Copyright (c) 2018 TwelveTone LLC
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
use Twelvetone\Common\ServiceManager;
27+
28+
{
29+
$manager = ServiceManager::getInstance();
30+
$grav = \Grav\Common\Grav::instance();
31+
$twig = $grav['twig'];
32+
33+
$manager->registerService("renderer", [
34+
"caption" => "Delete",
35+
"scope" => ["edit:section"],
36+
"order" => "last",
37+
"render" => function () {
38+
return "<a class='button' onclick='_doDelete(); return false;'><i class='fa fa-trash'></i>Delete</a>";
39+
},
40+
]);
41+
42+
$manager->registerService("renderer", [
43+
"caption" => "Fullscreen",
44+
"scope" => ["edit:section"],
45+
"order" => "last",
46+
"render" => function () use ($twig) {
47+
return $twig->processTemplate("fullscreen.html.twig", ["targetSelector" => "#edit-area"]);
48+
},
49+
]);
50+
51+
$manager->registerService("renderer", [
52+
"caption" => "Save+Back",
53+
"scope" => ["edit:section"],
54+
"order" => "first",
55+
"render" => function ($context) use ($twig) {
56+
return '<a class="button" onclick="_doSave();window.history.back();return false;"><i class="fa fa-reply"></i>Save+Back</a>';
57+
}
58+
]);
59+
60+
$manager->registerService("renderer", [
61+
"caption" => "Back And Refresh",
62+
"scope" => ["edit:section"],
63+
"order" => "first",
64+
"render" => function ($context) use ($twig) {
65+
// This will go back with refreshing but loose scroll position
66+
// return '<a class="button" onclick="window.location = document.referrer;"><i class="fa fa-reply"></i>Back</a>';
67+
// This will go back without refreshing but retain scroll position
68+
return '<a class="button" onclick="window.history.back()"><i class="fa fa-reply"></i>Back</a>';
69+
}
70+
]);
71+
$manager->registerService("renderer", [
72+
"caption" => "Save",
73+
"scope" => ["edit:section"],
74+
"order" => "last",
75+
"render" => function () {
76+
return "<a class='button' onclick='_doSave(); return false;'><i class='fa fa-save'></i>Save</a>";
77+
},
78+
]);
79+
}

0 commit comments

Comments
 (0)