1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-22 14:23:05 +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:
Ryan Cramer
2018-07-11 16:09:38 -04:00
parent 2e095c9cf4
commit be9d07c57b
3 changed files with 41 additions and 20 deletions

View File

@@ -2,7 +2,7 @@
* Alternate Select Multiple (asmSelect) 1.3 - jQuery Plugin
* 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.
*
@@ -16,6 +16,8 @@
listType: 'ol', // Ordered list 'ol', or unordered list 'ul'
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?
fieldset: false, // Use fieldset support? (for PW Fieldset types)
animate: false, // Animate the the adding/removing of items in the list?
@@ -75,6 +77,7 @@
function init() {
// 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)
while($("#" + options.containerClass + index).length > 0) index++;
@@ -84,6 +87,7 @@
.addClass($original.attr('class'))
.attr('name', options.selectClass + index)
.attr('id', options.selectClass + index);
if(!options.addable) $select.hide();
$selectRemoved = $("<select></select>");
@@ -332,7 +336,8 @@
if(!$O) return; // this is the first item, selectLabel
var $removeLink = $("<a></a>")
var $removeLink = null;
if(options.deletable) $removeLink = $("<a></a>")
.attr("href", "#")
.addClass(options.removeClass)
.prepend(options.removeLabel)
@@ -388,9 +393,9 @@
.addClass(options.listItemClass)
.append($itemLabel)
.append($itemDesc)
.append($itemStatus)
.append($removeLink)
.hide();
.append($itemStatus);
if($removeLink) $item.append($removeLink);
$item.hide();
if(options.jQueryUI) {
$item.addClass('ui-state-default')

File diff suppressed because one or more lines are too long

View File

@@ -14,11 +14,11 @@
* 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.
*
* 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.
*
*
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
* https://processwire.com
*
*
@@ -29,7 +29,7 @@ class MarkupPageArray extends WireData implements Module {
public static function getModuleInfo() {
return array(
'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,
'permanent' => false,
'singular' => true,
@@ -48,17 +48,24 @@ class MarkupPageArray extends WireData implements Module {
* Can be accessed as $mypages->render() where '$mypages' is any instance of a PageArray.
*
* Be sure to see the $defaultOptions in the method if you want to change it's behavior or output.
*
* @param HookEvent $event
*
* @param array $options Optional list of options to modify the behavior and output.
* @return string
* #param array $options Optional list of options to modify the behavior and output.
* #return string
*
*/
public function renderPageArray(HookEvent $event) {
$pageArray = $event->object;
if(!count($pageArray)) return '';
$arguments = $event->arguments;
/** @var PaginatedArray $pageArray */
$pageArray = $event->object;
$arguments = $event->arguments;
$options = array();
if(!count($pageArray)) {
$event->return = '';
return;
}
$defaultOptions = array(
@@ -91,14 +98,18 @@ class MarkupPageArray extends WireData implements Module {
$options = array_merge($defaultOptions, $options);
$out = '';
$fields = array();
if(preg_match_all('/\{[-_a-z0-9|]+\}/i', $options['itemMarkup'], $matches)) $fields = $matches[0];
else $fields = array();
if(preg_match_all('/\{[-_a-z0-9|]+\}/i', $options['itemMarkup'], $matches)) {
$fields = $matches[0];
}
foreach($pageArray as $page) {
if(!$page->viewable()) continue;
if($page instanceof Page && !$page->viewable()) continue;
$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']);
}
@@ -106,6 +117,7 @@ class MarkupPageArray extends WireData implements Module {
if(($options['pagerTop'] || $options['pagerBottom']) && $pageArray->getTotal() > count($pageArray)) {
/** @var MarkupPagerNav $pager */
$pager = $this->modules->get('MarkupPagerNav');
$pagerOptions = $options['pagerOptions'];
@@ -128,17 +140,21 @@ class MarkupPageArray extends WireData implements Module {
* Render pagination markup for a PageArray
*
* i.e. echo $mypages->renderPager(), where '$mypages' is a PageArray instance
*
* @param HookEvent $event
*
* @param array $options Optional options to provide to MarkupPagerNav - see MarkupPagerNav::$options
* @return string
* #param array $options Optional options to provide to MarkupPagerNav - see MarkupPagerNav::$options
* #return string
*
*/
public function renderPager(HookEvent $event) {
/** @var PaginatedArray $pageArray */
$pageArray = $event->object;
if(!$pageArray->getLimit()) return;
$arguments = $event->arguments;
$options = array();
if(isset($arguments[0]) && is_array($arguments[0])) $options = $arguments[0];
/** @var MarkupPagerNav $pager */
$pager = $this->modules->get('MarkupPagerNav');
if(empty($options['baseUrl'])) {
$baseUrl = $this->wire('page')->url;