mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Inline fixes
This commit is contained in:
parent
57acb83546
commit
aaf1130569
85
javascript/tmpl.js
Normal file
85
javascript/tmpl.js
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* JavaScript Templates 1.0.2
|
||||||
|
* https://github.com/blueimp/JavaScript-Templates
|
||||||
|
*
|
||||||
|
* Copyright 2011, Sebastian Tschan
|
||||||
|
* https://blueimp.net
|
||||||
|
*
|
||||||
|
* Licensed under the MIT license:
|
||||||
|
* http://www.opensource.org/licenses/MIT
|
||||||
|
*
|
||||||
|
* Inspired by John Resig's JavaScript Micro-Templating:
|
||||||
|
* http://ejohn.org/blog/javascript-micro-templating/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*jslint evil: true, regexp: true */
|
||||||
|
/*global document, define */
|
||||||
|
|
||||||
|
(function ($) {
|
||||||
|
"use strict";
|
||||||
|
var tmpl = function (str, data) {
|
||||||
|
var f = !/[^\-\w]/.test(str) ? tmpl.cache[str] = tmpl.cache[str] ||
|
||||||
|
tmpl(tmpl.load(str)) :
|
||||||
|
new Function(
|
||||||
|
tmpl.arg,
|
||||||
|
("var _s=''" + tmpl.helper + ";_s+='" +
|
||||||
|
str.replace(tmpl.regexp, tmpl.func) +
|
||||||
|
"';return _s;").split("_s+='';").join("")
|
||||||
|
);
|
||||||
|
f.tmpl = f.tmpl || tmpl;
|
||||||
|
return data ? f(data) : f;
|
||||||
|
};
|
||||||
|
tmpl.cache = {};
|
||||||
|
tmpl.load = function (id) {
|
||||||
|
return document.getElementById(id).innerHTML;
|
||||||
|
};
|
||||||
|
tmpl.regexp = /(\s+)|('|\\)(?![^%]*%\})|(?:\{%(=|#)(.+?)%\})|(\{%)|(%\})/g;
|
||||||
|
tmpl.func = function (s, p1, p2, p3, p4, p5, p6, o, str) {
|
||||||
|
if (p1) { // whitespace
|
||||||
|
return o && o + s.length !== str.length ? " " : "";
|
||||||
|
}
|
||||||
|
if (p2) { // single quote or backslash
|
||||||
|
return "\\" + s;
|
||||||
|
}
|
||||||
|
if (p3) { // interpolation: {%=prop%}, or unescaped: {%#prop%}
|
||||||
|
if (p3 === "=") {
|
||||||
|
return "'+_e(" + p4 + ")+'";
|
||||||
|
}
|
||||||
|
return "'+(" + p4 + "||'')+'";
|
||||||
|
}
|
||||||
|
if (p5) { // evaluation start tag: {%
|
||||||
|
return "';";
|
||||||
|
}
|
||||||
|
if (p6) { // evaluation end tag: %}
|
||||||
|
return "_s+='";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tmpl.encReg = /[<>&"\x00]/g;
|
||||||
|
tmpl.encMap = {
|
||||||
|
"<": "<",
|
||||||
|
">": ">",
|
||||||
|
"&": "&",
|
||||||
|
"\"": """,
|
||||||
|
"\x00": ""
|
||||||
|
};
|
||||||
|
tmpl.encode = function (s) {
|
||||||
|
return String(s || "").replace(
|
||||||
|
tmpl.encReg,
|
||||||
|
function (c) {
|
||||||
|
return tmpl.encMap[c];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
tmpl.arg = "o";
|
||||||
|
tmpl.helper = ",_t=arguments.callee.tmpl,_e=_t.encode" +
|
||||||
|
",print=function(s,e){_s+=e&&(s||'')||_e(s);}" +
|
||||||
|
",include=function(s,d){_s+=_t(s,d);}";
|
||||||
|
if (typeof define === "function" && define.amd) {
|
||||||
|
// Register as an AMD module:
|
||||||
|
define("tmpl", function () {
|
||||||
|
return tmpl;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$.tmpl = tmpl;
|
||||||
|
}
|
||||||
|
}(this));
|
@ -3,7 +3,6 @@
|
|||||||
namespace Symbiote\GridFieldExtensions;
|
namespace Symbiote\GridFieldExtensions;
|
||||||
|
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Core\Object;
|
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
||||||
@ -12,6 +11,7 @@ use SilverStripe\ORM\ArrayList;
|
|||||||
use SilverStripe\ORM\DataObjectInterface;
|
use SilverStripe\ORM\DataObjectInterface;
|
||||||
use SilverStripe\ORM\ManyManyList;
|
use SilverStripe\ORM\ManyManyList;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
@ -86,11 +86,11 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
|
|||||||
|
|
||||||
$fragment = $this->getFragment();
|
$fragment = $this->getFragment();
|
||||||
|
|
||||||
if (!$editable = $grid->getConfig()->getComponentByType('GridFieldEditableColumns')) {
|
if (!$editable = $grid->getConfig()->getComponentByType(GridFieldEditableColumns::class)) {
|
||||||
throw new Exception('Inline adding requires the editable columns component');
|
throw new Exception('Inline adding requires the editable columns component');
|
||||||
}
|
}
|
||||||
|
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/javascript-templates/tmpl.js');
|
Requirements::javascript('symbiote/silverstripe-gridfieldextensions:javascript/tmpl.js');
|
||||||
GridFieldExtensions::include_requirements();
|
GridFieldExtensions::include_requirements();
|
||||||
|
|
||||||
$data = new ArrayData(array(
|
$data = new ArrayData(array(
|
||||||
@ -109,7 +109,7 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
|
|||||||
$handled = array_keys($editable->getDisplayFields($grid));
|
$handled = array_keys($editable->getDisplayFields($grid));
|
||||||
|
|
||||||
if ($grid->getList()) {
|
if ($grid->getList()) {
|
||||||
$record = Object::create($grid->getModelClass());
|
$record = Injector::inst()->create($grid->getModelClass());
|
||||||
} else {
|
} else {
|
||||||
$record = null;
|
$record = null;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<% loop $Me %>
|
<% loop $Me %>
|
||||||
<% if $IsActions %>
|
<% if $IsActions %>
|
||||||
<td$Attributes>
|
<td$Attributes>
|
||||||
<button class="ss-gridfield-delete-inline gridfield-button-delete ss-ui-button" data-icon="cross-circle"></button>
|
<button class="ss-gridfield-delete-inline gridfield-button-delete action gridfield-button-delete btn--icon-md font-icon-trash-bin btn--no-text grid-field__icon-action form-group--no-label"></button>
|
||||||
</td>
|
</td>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td$Attributes>$Content</td>
|
<td$Attributes>$Content</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user