mirror of
https://github.com/processwire/processwire.git
synced 2025-08-22 22:34:15 +02:00
Add new "addable" and "deletable" options to AsmSelect, enabling you to have AsmSelects where the ability to add and/or delete items is suppressed. With both options disabled, it's useful for sorting fixed groups of items.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* Alternate Select Multiple (asmSelect) 1.3 - jQuery Plugin
|
* Alternate Select Multiple (asmSelect) 1.3 - jQuery Plugin
|
||||||
* http://www.ryancramer.com/projects/asmselect/
|
* http://www.ryancramer.com/projects/asmselect/
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2014 by Ryan Cramer - http://www.ryancramer.com
|
* Copyright (c) 2009-2018 by Ryan Cramer - http://www.ryancramer.com
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
*
|
*
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
listType: 'ol', // Ordered list 'ol', or unordered list 'ul'
|
listType: 'ol', // Ordered list 'ol', or unordered list 'ul'
|
||||||
sortable: false, // Should the list be sortable?
|
sortable: false, // Should the list be sortable?
|
||||||
|
addable: true, // Can items be added to selection?
|
||||||
|
deletable: true, // Can items be removed from selection?
|
||||||
highlight: false, // Use the highlight feature?
|
highlight: false, // Use the highlight feature?
|
||||||
fieldset: false, // Use fieldset support? (for PW Fieldset types)
|
fieldset: false, // Use fieldset support? (for PW Fieldset types)
|
||||||
animate: false, // Animate the the adding/removing of items in the list?
|
animate: false, // Animate the the adding/removing of items in the list?
|
||||||
@@ -75,6 +77,7 @@
|
|||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
// initialize the alternate select multiple
|
// initialize the alternate select multiple
|
||||||
|
if(options.deletable && !options.addable) options.hideDeleted = false;
|
||||||
|
|
||||||
// this loop ensures uniqueness, in case of existing asmSelects placed by ajax (1.0.3)
|
// this loop ensures uniqueness, in case of existing asmSelects placed by ajax (1.0.3)
|
||||||
while($("#" + options.containerClass + index).length > 0) index++;
|
while($("#" + options.containerClass + index).length > 0) index++;
|
||||||
@@ -84,6 +87,7 @@
|
|||||||
.addClass($original.attr('class'))
|
.addClass($original.attr('class'))
|
||||||
.attr('name', options.selectClass + index)
|
.attr('name', options.selectClass + index)
|
||||||
.attr('id', options.selectClass + index);
|
.attr('id', options.selectClass + index);
|
||||||
|
if(!options.addable) $select.hide();
|
||||||
|
|
||||||
$selectRemoved = $("<select></select>");
|
$selectRemoved = $("<select></select>");
|
||||||
|
|
||||||
@@ -332,7 +336,8 @@
|
|||||||
|
|
||||||
if(!$O) return; // this is the first item, selectLabel
|
if(!$O) return; // this is the first item, selectLabel
|
||||||
|
|
||||||
var $removeLink = $("<a></a>")
|
var $removeLink = null;
|
||||||
|
if(options.deletable) $removeLink = $("<a></a>")
|
||||||
.attr("href", "#")
|
.attr("href", "#")
|
||||||
.addClass(options.removeClass)
|
.addClass(options.removeClass)
|
||||||
.prepend(options.removeLabel)
|
.prepend(options.removeLabel)
|
||||||
@@ -388,9 +393,9 @@
|
|||||||
.addClass(options.listItemClass)
|
.addClass(options.listItemClass)
|
||||||
.append($itemLabel)
|
.append($itemLabel)
|
||||||
.append($itemDesc)
|
.append($itemDesc)
|
||||||
.append($itemStatus)
|
.append($itemStatus);
|
||||||
.append($removeLink)
|
if($removeLink) $item.append($removeLink);
|
||||||
.hide();
|
$item.hide();
|
||||||
|
|
||||||
if(options.jQueryUI) {
|
if(options.jQueryUI) {
|
||||||
$item.addClass('ui-state-default')
|
$item.addClass('ui-state-default')
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -14,11 +14,11 @@
|
|||||||
* It will also generate pagination if the selector had a limit placed on it (i.e. "limit=10"),
|
* It will also generate pagination if the selector had a limit placed on it (i.e. "limit=10"),
|
||||||
* and there are more pages left to render, and the page's template supports page numbers.
|
* and there are more pages left to render, and the page's template supports page numbers.
|
||||||
*
|
*
|
||||||
* Also adds a PageArray::renderPager() method, which is convenient when you are generating your
|
* Also adds a PaginatedArray::renderPager() method, which is convenient when you are generating your
|
||||||
* own page list markup, but just want to use the automatic pagination generator.
|
* own page list markup, but just want to use the automatic pagination generator.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@@ -29,7 +29,7 @@ class MarkupPageArray extends WireData implements Module {
|
|||||||
public static function getModuleInfo() {
|
public static function getModuleInfo() {
|
||||||
return array(
|
return array(
|
||||||
'title' => 'PageArray Markup',
|
'title' => 'PageArray Markup',
|
||||||
'summary' => 'Adds a render() method to all PageArray instances for basic unordered list generation of PageArrays.',
|
'summary' => 'Adds renderPager() method to all PaginatedArray types, for easy pagination output. Plus a render() method to PageArray instances.',
|
||||||
'version' => 100,
|
'version' => 100,
|
||||||
'permanent' => false,
|
'permanent' => false,
|
||||||
'singular' => true,
|
'singular' => true,
|
||||||
@@ -49,17 +49,24 @@ class MarkupPageArray extends WireData implements Module {
|
|||||||
*
|
*
|
||||||
* Be sure to see the $defaultOptions in the method if you want to change it's behavior or output.
|
* Be sure to see the $defaultOptions in the method if you want to change it's behavior or output.
|
||||||
*
|
*
|
||||||
* @param array $options Optional list of options to modify the behavior and output.
|
* @param HookEvent $event
|
||||||
* @return string
|
*
|
||||||
|
* #param array $options Optional list of options to modify the behavior and output.
|
||||||
|
* #return string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function renderPageArray(HookEvent $event) {
|
public function renderPageArray(HookEvent $event) {
|
||||||
|
|
||||||
|
/** @var PaginatedArray $pageArray */
|
||||||
$pageArray = $event->object;
|
$pageArray = $event->object;
|
||||||
if(!count($pageArray)) return '';
|
|
||||||
$arguments = $event->arguments;
|
$arguments = $event->arguments;
|
||||||
$options = array();
|
$options = array();
|
||||||
|
|
||||||
|
if(!count($pageArray)) {
|
||||||
|
$event->return = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$defaultOptions = array(
|
$defaultOptions = array(
|
||||||
|
|
||||||
// markup for the list container, specify {out} where generated items should go
|
// markup for the list container, specify {out} where generated items should go
|
||||||
@@ -91,14 +98,18 @@ class MarkupPageArray extends WireData implements Module {
|
|||||||
$options = array_merge($defaultOptions, $options);
|
$options = array_merge($defaultOptions, $options);
|
||||||
|
|
||||||
$out = '';
|
$out = '';
|
||||||
|
$fields = array();
|
||||||
|
|
||||||
if(preg_match_all('/\{[-_a-z0-9|]+\}/i', $options['itemMarkup'], $matches)) $fields = $matches[0];
|
if(preg_match_all('/\{[-_a-z0-9|]+\}/i', $options['itemMarkup'], $matches)) {
|
||||||
else $fields = array();
|
$fields = $matches[0];
|
||||||
|
}
|
||||||
|
|
||||||
foreach($pageArray as $page) {
|
foreach($pageArray as $page) {
|
||||||
if(!$page->viewable()) continue;
|
if($page instanceof Page && !$page->viewable()) continue;
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach($fields as $field) $values[$field] = $page->get(trim($field, '{}'));
|
foreach($fields as $field) {
|
||||||
|
$values[$field] = $page->get(trim($field, '{}'));
|
||||||
|
}
|
||||||
$out .= str_replace($fields, $values, $options['itemMarkup']);
|
$out .= str_replace($fields, $values, $options['itemMarkup']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +117,7 @@ class MarkupPageArray extends WireData implements Module {
|
|||||||
|
|
||||||
if(($options['pagerTop'] || $options['pagerBottom']) && $pageArray->getTotal() > count($pageArray)) {
|
if(($options['pagerTop'] || $options['pagerBottom']) && $pageArray->getTotal() > count($pageArray)) {
|
||||||
|
|
||||||
|
/** @var MarkupPagerNav $pager */
|
||||||
$pager = $this->modules->get('MarkupPagerNav');
|
$pager = $this->modules->get('MarkupPagerNav');
|
||||||
$pagerOptions = $options['pagerOptions'];
|
$pagerOptions = $options['pagerOptions'];
|
||||||
|
|
||||||
@@ -129,16 +141,20 @@ class MarkupPageArray extends WireData implements Module {
|
|||||||
*
|
*
|
||||||
* i.e. echo $mypages->renderPager(), where '$mypages' is a PageArray instance
|
* i.e. echo $mypages->renderPager(), where '$mypages' is a PageArray instance
|
||||||
*
|
*
|
||||||
* @param array $options Optional options to provide to MarkupPagerNav - see MarkupPagerNav::$options
|
* @param HookEvent $event
|
||||||
* @return string
|
*
|
||||||
|
* #param array $options Optional options to provide to MarkupPagerNav - see MarkupPagerNav::$options
|
||||||
|
* #return string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function renderPager(HookEvent $event) {
|
public function renderPager(HookEvent $event) {
|
||||||
|
/** @var PaginatedArray $pageArray */
|
||||||
$pageArray = $event->object;
|
$pageArray = $event->object;
|
||||||
if(!$pageArray->getLimit()) return;
|
if(!$pageArray->getLimit()) return;
|
||||||
$arguments = $event->arguments;
|
$arguments = $event->arguments;
|
||||||
$options = array();
|
$options = array();
|
||||||
if(isset($arguments[0]) && is_array($arguments[0])) $options = $arguments[0];
|
if(isset($arguments[0]) && is_array($arguments[0])) $options = $arguments[0];
|
||||||
|
/** @var MarkupPagerNav $pager */
|
||||||
$pager = $this->modules->get('MarkupPagerNav');
|
$pager = $this->modules->get('MarkupPagerNav');
|
||||||
if(empty($options['baseUrl'])) {
|
if(empty($options['baseUrl'])) {
|
||||||
$baseUrl = $this->wire('page')->url;
|
$baseUrl = $this->wire('page')->url;
|
||||||
|
Reference in New Issue
Block a user