mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 11:26:04 +01:00
Merge branch 'develop' into feature/admin-gpm-dependencies
This commit is contained in:
@@ -261,7 +261,7 @@ class Admin
|
||||
* @return Data\Data|null
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function data($type, $post = array())
|
||||
public function data($type, array $post = [])
|
||||
{
|
||||
static $data = [];
|
||||
|
||||
@@ -270,7 +270,7 @@ class Admin
|
||||
}
|
||||
|
||||
if (!$post) {
|
||||
$post = isset($_POST) ? $_POST : [];
|
||||
$post = isset($_POST['data']) ? $_POST['data'] : [];
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
|
||||
@@ -52,6 +52,11 @@ class AdminController
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @var Admin
|
||||
*/
|
||||
@@ -79,6 +84,10 @@ class AdminController
|
||||
$this->grav = $grav;
|
||||
$this->view = $view;
|
||||
$this->task = $task ? $task : 'display';
|
||||
if (isset($post['data'])) {
|
||||
$this->data = $this->getPost($post['data']);
|
||||
unset($post['data']);
|
||||
}
|
||||
$this->post = $this->getPost($post);
|
||||
$this->route = $route;
|
||||
$this->admin = $this->grav['admin'];
|
||||
@@ -1015,7 +1024,7 @@ class AdminController
|
||||
|
||||
// Filter value and save it.
|
||||
$this->post = ['enabled' => true];
|
||||
$obj = $this->prepareData();
|
||||
$obj = $this->prepareData($this->post);
|
||||
$obj->save();
|
||||
|
||||
$this->post = ['_redirect' => 'plugins'];
|
||||
@@ -1041,7 +1050,7 @@ class AdminController
|
||||
|
||||
// Filter value and save it.
|
||||
$this->post = ['enabled' => false];
|
||||
$obj = $this->prepareData();
|
||||
$obj = $this->prepareData($this->post);
|
||||
$obj->save();
|
||||
|
||||
$this->post = ['_redirect' => 'plugins'];
|
||||
@@ -1266,7 +1275,7 @@ class AdminController
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->post;
|
||||
$data = (array) $this->data;
|
||||
|
||||
if ($data['route'] == '/') {
|
||||
$path = $this->grav['locator']->findResource('page://');
|
||||
@@ -1345,7 +1354,7 @@ class AdminController
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->post;
|
||||
$data = (array) $this->data;
|
||||
|
||||
$config = $this->grav['config'];
|
||||
|
||||
@@ -1417,7 +1426,7 @@ class AdminController
|
||||
|
||||
} else {
|
||||
// Handle standard data types.
|
||||
$obj = $this->prepareData();
|
||||
$obj = $this->prepareData($data);
|
||||
$obj = $this->processFiles($obj);
|
||||
$obj->validate();
|
||||
$obj->filter();
|
||||
@@ -1501,7 +1510,7 @@ class AdminController
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->post;
|
||||
$data = (array) $this->data;
|
||||
$route = $data['route'] != '/' ? $data['route'] : '';
|
||||
$folder = ltrim($data['folder'], '_');
|
||||
if (!empty($data['modular'])) {
|
||||
@@ -1684,7 +1693,7 @@ class AdminController
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->post;
|
||||
$data = (array) $this->data;
|
||||
$language = $data['lang'];
|
||||
|
||||
if ($language) {
|
||||
@@ -1824,7 +1833,7 @@ class AdminController
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function &getPost($post)
|
||||
protected function getPost($post)
|
||||
{
|
||||
unset($post['task']);
|
||||
|
||||
@@ -1874,10 +1883,10 @@ class AdminController
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected function prepareData()
|
||||
protected function prepareData(array $data)
|
||||
{
|
||||
$type = trim("{$this->view}/{$this->admin->route}", '/');
|
||||
$data = $this->admin->data($type, $this->post);
|
||||
$data = $this->admin->data($type, $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -1927,7 +1936,7 @@ class AdminController
|
||||
*/
|
||||
protected function preparePage(Page $page, $clean_header = false, $language = '')
|
||||
{
|
||||
$input = $this->post;
|
||||
$input = (array) $this->data;
|
||||
|
||||
if (isset($input['order'])) {
|
||||
$order = max(0, (int)isset($input['order']) ? $input['order'] : $page->value('order'));
|
||||
|
||||
@@ -29,9 +29,12 @@ export default class ColorpickerField {
|
||||
}
|
||||
|
||||
let target = field.closest(this.options.update);
|
||||
if (!target.lenght) {
|
||||
if (!target.length) {
|
||||
target = field.siblings(this.options.update);
|
||||
}
|
||||
if (!target.length) {
|
||||
target = field.parent('.g-colorpicker').find(this.options.update);
|
||||
}
|
||||
|
||||
target.css({ backgroundColor });
|
||||
});
|
||||
@@ -40,7 +43,7 @@ export default class ColorpickerField {
|
||||
|
||||
attach() {
|
||||
body.on(FOCUSIN, this.selector, (event) => this.show(event, event.currentTarget));
|
||||
body.on(MOUSEDOWN, '.g-colorpicker i', this.bound('iconClick'));
|
||||
body.on(MOUSEDOWN, '.g-colorpicker, .g-colorpicker i', this.bound('iconClick'));
|
||||
body.on('keydown', this.selector, (event) => {
|
||||
switch (event.keyCode) {
|
||||
case 9: // tab
|
||||
@@ -155,13 +158,11 @@ export default class ColorpickerField {
|
||||
});
|
||||
}
|
||||
|
||||
iconClick(event, element) {
|
||||
iconClick(event) {
|
||||
event && event.preventDefault();
|
||||
|
||||
let input = $(event.currentTarget).siblings('input');
|
||||
input.focus();
|
||||
|
||||
this.show(event, input);
|
||||
let input = $(event.currentTarget).find('input');
|
||||
setTimeout(() => input.focus(), 50);
|
||||
}
|
||||
|
||||
bodyMove(event) {
|
||||
|
||||
@@ -20,13 +20,6 @@ export default class Form {
|
||||
}
|
||||
}); */
|
||||
|
||||
// clear out any `noform` field from its name
|
||||
this.form.on('submit', () => {
|
||||
$('.no-form').attr('name', null);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
this._attachShortcuts();
|
||||
this._attachToggleables();
|
||||
this._attachDisabledFields();
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
themes/grav/css-compiled/template.css
vendored
2
themes/grav/css-compiled/template.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
themes/grav/js/admin.min.js
vendored
2
themes/grav/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -11,11 +11,32 @@
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
top: 15px;
|
||||
right: 10px;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.g-colorpicker-preview-wrap {
|
||||
cursor: default;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 43px;
|
||||
height: 43px;
|
||||
border-radius: 0 3px 3px 0;
|
||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
|
||||
}
|
||||
|
||||
.g-colorpicker-preview {
|
||||
position: absolute;
|
||||
top: -1px;
|
||||
right: -1px;
|
||||
bottom: -1px;
|
||||
left: -1px;
|
||||
border-radius: 0 3px 3px 0;
|
||||
}
|
||||
|
||||
&.light-text {
|
||||
input, i {
|
||||
color: $white;
|
||||
@@ -31,7 +52,7 @@
|
||||
.cp-wrapper {
|
||||
position: absolute;
|
||||
width: 173px;
|
||||
height: 205px;
|
||||
height: 208px;
|
||||
background: white;
|
||||
border: solid 1px #CCC;
|
||||
box-shadow: 0 0 20px rgba(0, 0, 0, .2);
|
||||
@@ -234,3 +255,7 @@
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
|
||||
.g-colorpicker-preview-wrap {
|
||||
background-image: url(data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQECAgICAgICAgICAgMDAwMDAwMDAwP/2wBDAQEBAQEBAQIBAQICAgECAgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwP/wAARCAAyADIDAREAAhEBAxEB/8QAGgABAAMBAQEAAAAAAAAAAAAAAAQFBwYJCv/EAD4QAAAGAAUBBQQGBwkAAAAAAAECAwQFBhITFBUWCAARGCU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b0hm9jbYrFyCi6VqNHUEjVrMIpsW7Z1EC9cqVxcWxRfAmcDkxnTETAUJtw96HbuAeUcH1e7cw8v1HJtLoNu2XkGblcfWzs3Jw4iYcXebCE2QtkddKqn05xaL1vd2bKNqaspIJoJVU0jQTtXUwsm+buXUuLJynXFwbGFiChxOTGRMBMJQVO2R3TVHLUW9IvZaXlnqlsbuKmmg+jiRz5BtDoorLTDmBclelcwKxjFKiZMEzEEDiImKUKWp1OR6apFa9XpZlLREsyUqbdvU1F30iSRfLtphFZZGYbQLYrIraBWKYxVjKAoYgAQQExihoXix9nX3Ldfw6C+Y+wOrH6uoX41jvyKx9gUH7LD/4K9pX9ZauwcV0f/3h/wAJf9m7BxVB+1O/+NfaV/R2rsDqx+sWF+Co789sfYNq6sfq6hfjWO/IrH2Dz27B/9k=);
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
{% block contents %}
|
||||
<div class="form-label{% if not vertical %} block size-1-3{% endif %}">
|
||||
{% if field.toggleable %}
|
||||
<span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ field.name|fieldName }}">
|
||||
<span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ (scope ~ field.name)|fieldName }}">
|
||||
<input type="checkbox"
|
||||
id="toggleable_{{ field.name }}"
|
||||
{% if toggleableChecked %}value="1"{% endif %}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{% extends "forms/field.html.twig" %}
|
||||
|
||||
{% block global_attributes %}
|
||||
data-grav-array-name="{{ field.name|fieldName }}"
|
||||
data-grav-array-name="{{ (scope ~ field.name)|fieldName }}"
|
||||
data-grav-array-keyname="{{ field.placeholder_key|e|tu }}"
|
||||
data-grav-array-valuename="{{ field.placeholder_value|e|tu }}"
|
||||
{{ parent() }}
|
||||
{% endblock %}
|
||||
|
||||
{% macro renderer(key, text, field) %}
|
||||
{% macro renderer(key, text, field, scope) %}
|
||||
<div class="form-row{% if field.value_only %} array-field-value_only{% endif %}"
|
||||
data-grav-array-type="row">
|
||||
{% if field.value_only != true %}
|
||||
@@ -25,7 +25,7 @@
|
||||
<input
|
||||
data-grav-array-type="value"
|
||||
type="text"
|
||||
name="{{ (field.name|fieldName) ~ '[' ~ key ~ ']' }}"
|
||||
name="{{ ((scope ~ field.name)|fieldName) ~ '[' ~ key ~ ']' }}"
|
||||
placeholder="{{ field.placeholder_value|e|tu }}"
|
||||
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
|
||||
value={% if text == 'true' %}true{% elseif text == 'false' %}false{% else %}"{{ text|join(', ')|e }}"{% endif %} />
|
||||
@@ -41,11 +41,11 @@
|
||||
{% if value|length %}
|
||||
{% for key, text in value -%}
|
||||
{% if text is not iterable %}
|
||||
{{ array_field.renderer(key, text, field) }}
|
||||
{{ array_field.renderer(key, text, field, scope) }}
|
||||
{% else %}
|
||||
{# Backward compatibility for nested arrays (metas) which are not supported anymore #}
|
||||
{% for subkey, subtext in text -%}
|
||||
{{ array_field.renderer(key ~ ':' ~ subkey, subtext, field) }}
|
||||
{{ array_field.renderer(key ~ ':' ~ subkey, subtext, field, scope) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
@@ -60,7 +60,7 @@
|
||||
<input
|
||||
data-grav-array-type="value"
|
||||
type="text"
|
||||
name="{{ field.name|fieldName }}"
|
||||
name="{{ (scope ~ field.name)|fieldName }}"
|
||||
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
|
||||
placeholder="{{ field.placeholder_value|e|tu }}" />
|
||||
<span data-grav-array-action="rem" class="fa fa-minus"></span>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{% extends "forms/field.html.twig" %}
|
||||
{% set originalValue = originalValue is defined ? originalValue : value %}
|
||||
{% set value = (value is null ? field.default : value) %}
|
||||
{% set pattern = '^#([a-fA-F0-9]{6})|(rgba\\(\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*((0.[0-9]+)|[01])\\s*\\))$' %}
|
||||
|
||||
{% block input %}
|
||||
<div class="form-list-wrapper {{ field.size }}" data-type="collection">
|
||||
<div class="g-colorpicker">
|
||||
<input
|
||||
data-grav-colorpicker="{{ {update: '.g-colorpicker-preview-wrap .g-colorpicker-preview'}|json_encode|e('html_attr') }}"
|
||||
{# required attribute structures #}
|
||||
name="{{ (scope ~ field.name)|fieldName }}"
|
||||
value="{{ value|e('html_attr')|join(', ') }}"
|
||||
type="text"
|
||||
{# input attribute structures #}
|
||||
{% block input_attributes %}
|
||||
{% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
|
||||
{% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
|
||||
{% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
|
||||
{% if field.disabled %}disabled="disabled"{% endif %}
|
||||
{% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %}
|
||||
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
|
||||
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
|
||||
{% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
|
||||
{% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
|
||||
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
|
||||
pattern="{{ field.validate.pattern|default(pattern)|raw }}"
|
||||
{% if field.validate.message %}title="{{ field.validate.message|e|t }}"
|
||||
{% elseif field.title is defined %}title="{{ field.title|e|t }}" {% endif %}
|
||||
{% endblock %}
|
||||
/>
|
||||
<div class="g-colorpicker-preview-wrap">
|
||||
<div class="g-colorpicker-preview" style="background-color: {{ value|e }}"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% set value = (value is null ? field.default : value) %}
|
||||
{% set name = scope ~ field.name %}
|
||||
{% set name = field.name %}
|
||||
{% set btnLabel = field.btnLabel is defined ? field.btnLabel : "PLUGIN_ADMIN.ADD_ITEM" %}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
{% block global_attributes %}
|
||||
{{ parent() }}
|
||||
data-grav-field-name="{{ field.name|fieldName }}"
|
||||
data-grav-field-name="{{ (scope ~ field.name)|fieldName }}"
|
||||
{% endblock %}
|
||||
|
||||
{% macro spanToggle(input, length) %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% set form_id = form_id ? form_id : 'blueprints' %}
|
||||
{% set scope = scope ?: 'data.' %}
|
||||
|
||||
<form id="{{ form_id }}" method="post" data-grav-form="{{ form_id }}" data-grav-keepalive="true">
|
||||
{% for field in blueprints.fields %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% set form_id = form_id ? form_id : 'blueprints' %}
|
||||
{% set scope = scope ?: 'data.' %}
|
||||
|
||||
<form id="{{ form_id }}" method="post" data-grav-form="{{ form_id }}" data-grav-keepalive="true">
|
||||
{% for field in blueprints.fields %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% set form_id = form_id ? form_id : 'blueprints' %}
|
||||
{% set scope = scope ?: 'data.' %}
|
||||
|
||||
<form id="{{ form_id }}" method="post" data-grav-form="{{ form_id }}" data-grav-keepalive="true">
|
||||
{% for field in blueprints.fields %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% set form_id = form_id ? form_id : 'blueprints' %}
|
||||
{% set scope = scope ?: 'data.' %}
|
||||
|
||||
{% set multipart = '' %}
|
||||
{% for field in blueprints.fields %}
|
||||
|
||||
Reference in New Issue
Block a user