$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
$links = CRM_Custom_Page_Option::actionLinks();
- $fields = array('id', 'label', 'value', 'weight');
+ $fields = array('id', 'label', 'value');
$config = CRM_Core_Config::singleton();
while ($dao->fetch()) {
$options[$dao->id] = array();
$dao->id
);
}
- // Add order changing widget to selector
- $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field/option',
- "reset=1&action=browse&gid={$params['gid']}&fid={$params['fid']}"
- );
- $filter = "option_group_id = {$optionGroupID}";
- CRM_Utils_Weight::addOrder($options, 'CRM_Core_DAO_OptionValue',
- 'id', $returnURL, $filter
- );
return $options;
}
<page_callback>CRM_Custom_Page_AJAX::getOptionList</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
+ <item>
+ <path>civicrm/ajax/reorder</path>
+ <page_callback>CRM_Custom_Page_AJAX::fixOrdering</page_callback>
+ <access_arguments>access CiviCRM</access_arguments>
+ </item>
</menu>
0 => 'options.label',
1 => 'options.value',
2 => '',
- 3 => 'options.weight',
+ 3 => '',
4 => '',
- 5 => '',
);
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
'label',
'value',
'is_default',
- 'weight',
'is_active',
'links',
'class',
CRM_Utils_System::civiExit();
}
+ /**
+ * Fix Ordering of options
+ *
+ */
+
+ public static function fixOrdering() {
+ $params = $_REQUEST;
+
+ $queryParams = array(
+ 1 => array($params['start'], 'Integer'),
+ 2 => array($params['end'], 'Integer'),
+ 3 => array($params['gid'], 'Integer'),
+ );
+ $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
+ $startid = CRM_Core_DAO::singleValueQuery($dao, $queryParams);
+
+ $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
+ $endid = CRM_Core_DAO::singleValueQuery($dao2, $queryParams);
+
+ $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid";
+ CRM_Core_DAO::executeQuery($query, $queryParams);
+
+ // increment or decrement the rest by one
+ if ($params['start'] < $params['end']) {
+ $updateRows = "UPDATE civicrm_option_value
+ SET weight = weight - 1
+ WHERE weight > %1 AND weight < %2 AND option_group_id = %3
+ OR id = $endid";
+ }
+ else {
+ $updateRows = "UPDATE civicrm_option_value
+ SET weight = weight + 1
+ WHERE weight < %1 AND weight > %2 AND option_group_id = %3
+ OR id = $endid";
+ }
+ CRM_Core_DAO::executeQuery($updateRows, $queryParams);
+ }
+
}
CRM_Utils_System::setTitle($newTitle);
$this->assign('reusedNames', $reusedNames);
}
+ $this->assign('optionGroupID', $optionGroupID);
}
/**
<th class='crm-custom_option-label'>{ts}Label{/ts}</th>
<th class='crm-custom_option-value'>{ts}Value{/ts}</th>
<th class='crm-custom_option-default_value'>{ts}Default{/ts}</th>
- <th class='nowrap crm-custom_option-weight'>{ts}Order{/ts}</th>
<th class='crm-custom_option-is_active nosort'>{ts}Enabled?{/ts}</th>
<th class='crm-custom_option-links'> </th>
<th class='hiddenElement'> </th>
{sClass:'crm-custom_option-label'},
{sClass:'crm-custom_option-value'},
{sClass:'crm-custom_option-default_value', bSortable:false},
- {sClass:'crm-custom_option-weight'},
{sClass:'crm-custom_option-is_active', bSortable:false},
{sClass:'crm-custom_option-links', bSortable:false},
{sClass:'hiddenElement', bSortable:false}
var id = $('td:last', nRow).text().split(',')[0];
var cl = $('td:last', nRow).text().split(',')[1];
$(nRow).addClass(cl).attr({id: 'OptionValue-' + id});
+ $('td:eq(0)', nRow).wrapInner('<span class="crm-editable crmf-label" />');
$('td:eq(2)', nRow).addClass('crmf-default_value');
- $('td:eq(3)', nRow).addClass('crmf-weight');
return nRow;
},
+ "fnDrawCallback": function() {
+ // FIXME: trigger crmLoad and crmEditable would happen automatically
+ $('.crm-editable').crmEditable();
+ },
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
}
});
}
+
+ var startPosition;
+ var endPosition;
+ var gid = {/literal}'{$optionGroupID}'{literal};
+
+ $("table.crm-option-selector tbody").sortable({
+ cursor: "move",
+ start:function(event, ui) {
+ var oSettings = $('table.crm-option-selector').dataTable().fnSettings();
+ var index = oSettings._iDisplayStart;
+ startPosition = index + ui.item.prevAll().length + 1;
+ },
+ update: function(event, ui) {
+ var oSettings = $('table.crm-option-selector').dataTable().fnSettings();
+ var index = oSettings._iDisplayStart;
+ endPosition = index + ui.item.prevAll().length + 1;
+
+ $.getJSON(CRM.url('civicrm/ajax/reorder'), {
+ returnFormat:'JSON',
+ start:startPosition,
+ end: endPosition,
+ gid: gid
+ })
+ }
+ });
});
</script>