diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 89e209ef509c046d922345914a70b255a16a5892..af36795fafecf615ba9ad47f98cfc4284fb15278 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -820,10 +820,17 @@ class DynamicList extends VerySimpleModel { return $this->get('name') . 's'; } + function getAllItems() { + return DynamicListItem::objects()->filter( + array('list_id'=>$this->get('id'))) + ->order_by($this->getListOrderBy()); + } + function getItems($limit=false, $offset=false) { if (!$this->_items) { $this->_items = DynamicListItem::objects()->filter( - array('list_id'=>$this->get('id'))) + array('list_id'=>$this->get('id'), + 'status__hasbit'=>DynamicListItem::ENABLED)) ->order_by($this->getListOrderBy()); if ($limit) $this->_items->limit($limit); @@ -910,6 +917,31 @@ class DynamicListItem extends VerySimpleModel { var $_config; var $_form; + const ENABLED = 0x0001; + + protected function hasStatus($flag) { + return 0 !== ($this->get('status') & $flag); + } + + protected function clearStatus($flag) { + return $this->set('status', $this->get('status') & ~$flag); + } + + protected function setStatus($flag) { + return $this->set('status', $this->get('status') | $flag); + } + + function isEnabled() { + return $this->hasStatus(self::ENABLED); + } + + function enable() { + $this->setStatus(self::ENABLED); + } + function disable() { + $this->clearStatus(self::ENABLED); + } + function getConfiguration() { if (!$this->_config) { $this->_config = $this->get('properties'); @@ -1049,6 +1081,10 @@ class SelectionField extends FormField { $this->_choices = array(); foreach ($this->getList()->getItems() as $i) $this->_choices[$i->get('id')] = $i->get('value'); + if ($this->value && !isset($this->_choices[$this->value])) { + $v = DynamicListItem::lookup($this->value); + $this->_choices[$v->get('id')] = $v->get('value').' (Disabled)'; + } } return $this->_choices; } diff --git a/include/class.orm.php b/include/class.orm.php index a5035bc3edd1575a5076c918f70b235a8fb21048..e2864143e049e5e8b9ca788e44953e336b774330 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -725,6 +725,7 @@ class MySqlCompiler extends SqlCompiler { 'lte' => '%1$s <= %2$s', 'isnull' => '%1$s IS NULL', 'like' => '%1$s LIKE %2$s', + 'hasbit' => '%1$s & %2$s != 0', 'in' => array('self', '__in'), ); diff --git a/include/staff/dynamic-list.inc.php b/include/staff/dynamic-list.inc.php index 6ae07c06eadc2a6bbff6004db4523efec61d3596..ffeb871e62f0321b619458e12b91b39593cd590e 100644 --- a/include/staff/dynamic-list.inc.php +++ b/include/staff/dynamic-list.inc.php @@ -198,7 +198,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); else $showing = 'Add a few initial items to the list'; ?> <tr> - <th colspan="4"> + <th colspan="5"> <em><?php echo $showing; ?></em> </th> </tr> @@ -206,6 +206,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <th></th> <th>Value</th> <th>Extra <em style="display:inline">— abbreviations and such</em></th> + <th>Disabled</th> <th>Delete</th> </tr> </thead> @@ -216,9 +217,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); $icon = ($info['sort_mode'] == 'SortCol') ? '<i class="icon-sort"></i> ' : ''; if ($list) { - foreach ($list->getItems() as $i) { + foreach ($list->getAllItems() as $i) { $id = $i->get('id'); ?> - <tr> + <tr class="<?php if (!$i->isEnabled()) echo 'disabled'; ?>"> <td><?php echo $icon; ?> <input type="hidden" name="sort-<?php echo $id; ?>" value="<?php echo $i->get('sort'); ?>"/></td> @@ -237,6 +238,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php } ?></td> <td><input type="text" size="30" name="extra-<?php echo $id; ?>" value="<?php echo $i->get('extra'); ?>"/></td> + <td> + <input type="checkbox" name="disable-<?php echo $id; ?>" <?php + if (!$i->isEnabled()) echo 'checked="checked"'; ?>/></td> <td> <input type="checkbox" name="delete-<?php echo $id; ?>"/></td> </tr> @@ -249,6 +253,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <td><input type="text" size="40" name="value-new-<?php echo $i; ?>"/></td> <td><input type="text" size="30" name="extra-new-<?php echo $i; ?>"/></td> <td></td> + <td></td> </tr> <?php } ?> </tbody> diff --git a/scp/css/scp.css b/scp/css/scp.css index 55b706178234fb2d8a20134cbb55f35553176d2c..c73e107cf7fa7b7d8c54417541f7490909acc36a 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -1629,3 +1629,9 @@ div.selected-signature .inner { background: #fc9f41; /* Old browsers */ color: rgba(255,255,255,0.8) !important; } + +tr.disabled td, +tr.disabled th { + opacity: 0.6; + background: #f5f5f5; +} diff --git a/scp/lists.php b/scp/lists.php index 79748a709eea0f9757649cf0874dfef9d7ebe3cb..17f36d18bb2fbe7ca6df5615e50071967e1e03f4 100644 --- a/scp/lists.php +++ b/scp/lists.php @@ -28,7 +28,7 @@ if($_POST) { else $errors['err'] = 'Unable to update custom list. Unknown internal error'; - foreach ($list->getItems() as $item) { + foreach ($list->getAllItems() as $item) { $id = $item->get('id'); if ($_POST["delete-$id"] == 'on') { $item->delete(); @@ -37,6 +37,12 @@ if($_POST) { foreach (array('sort','value','extra') as $i) if (isset($_POST["$i-$id"])) $item->set($i, $_POST["$i-$id"]); + + if ($_POST["disable-$id"] == 'on') + $item->disable(); + else + $item->enable(); + $item->save(); }