| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.7 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 6 | +--------------------------------------------------------------------+ |
| 7 | | This file is a part of CiviCRM. | |
| 8 | | | |
| 9 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 10 | | under the terms of the GNU Affero General Public License | |
| 11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 12 | | | |
| 13 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 16 | | See the GNU Affero General Public License for more details. | |
| 17 | | | |
| 18 | | You should have received a copy of the GNU Affero General Public | |
| 19 | | License and the CiviCRM Licensing Exception along | |
| 20 | | with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | *} |
| 26 | {if $action eq 1 or $action eq 2 or $action eq 4 or $action eq 8} |
| 27 | {include file="CRM/Custom/Form/Option.tpl"} |
| 28 | {else} |
| 29 | {if $reusedNames} |
| 30 | <div class="message status"> |
| 31 | <div class="icon inform-icon"></div> {ts 1=$reusedNames}These Multiple Choice Options are shared by the following custom fields: %1{/ts} |
| 32 | </div> |
| 33 | {/if} |
| 34 | |
| 35 | <div id="field_page"> |
| 36 | <p></p> |
| 37 | <div class="form-item"> |
| 38 | {* handle enable/disable actions*} |
| 39 | {include file="CRM/common/enableDisableApi.tpl"} |
| 40 | <table class="crm-option-selector"> |
| 41 | <thead> |
| 42 | <tr class="columnheader"> |
| 43 | <th class='crm-custom_option-label'>{ts}Label{/ts}</th> |
| 44 | <th class='crm-custom_option-value'>{ts}Value{/ts}</th> |
| 45 | <th class='crm-custom_option-default_value'>{ts}Default{/ts}</th> |
| 46 | <th class='crm-custom_option-is_active'>{ts}Enabled?{/ts}</th> |
| 47 | <th class='crm-custom_option-links'> </th> |
| 48 | <th class='hiddenElement'> </th> |
| 49 | </tr> |
| 50 | </thead> |
| 51 | </table> |
| 52 | {literal} |
| 53 | <script type="text/javascript"> |
| 54 | CRM.$(function($) { |
| 55 | var crmOptionSelector; |
| 56 | |
| 57 | buildOptions(); |
| 58 | |
| 59 | function buildOptions() { |
| 60 | var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/optionlist" h=0 q="snippet=4&fid=$fid&gid=$gid"}'{literal}; |
| 61 | var $context = $('.crm-ajax-container'); |
| 62 | var ZeroRecordText = {/literal}'{ts escape="js"}None found.{/ts}'{literal}; |
| 63 | |
| 64 | crmOptionSelector = $('table.crm-option-selector', $context).dataTable({ |
| 65 | "destroy" : true, |
| 66 | "bFilter" : false, |
| 67 | "bAutoWidth" : false, |
| 68 | "aaSorting" : [], |
| 69 | "aoColumns" : [ |
| 70 | {sClass:'crm-custom_option-label'}, |
| 71 | {sClass:'crm-custom_option-value'}, |
| 72 | {sClass:'crm-custom_option-default_value'}, |
| 73 | {sClass:'crm-custom_option-is_active'}, |
| 74 | {sClass:'crm-custom_option-links'}, |
| 75 | {sClass:'hiddenElement'} |
| 76 | ], |
| 77 | "bProcessing": true, |
| 78 | "asStripClasses" : [ "odd-row", "even-row" ], |
| 79 | "sPaginationType": "full_numbers", |
| 80 | "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>', |
| 81 | "bServerSide": true, |
| 82 | "bJQueryUI": true, |
| 83 | "bSort" : false, |
| 84 | "sAjaxSource": sourceUrl, |
| 85 | "iDisplayLength": 10, |
| 86 | "oLanguage": { |
| 87 | "sZeroRecords": ZeroRecordText, |
| 88 | "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal}, |
| 89 | "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal}, |
| 90 | "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal}, |
| 91 | "oPaginate": { |
| 92 | "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal}, |
| 93 | "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal}, |
| 94 | "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal}, |
| 95 | "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal} |
| 96 | } |
| 97 | }, |
| 98 | "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { |
| 99 | var id = $('td:last', nRow).text().split(',')[0]; |
| 100 | var cl = $('td:last', nRow).text().split(',')[1]; |
| 101 | $(nRow).addClass(cl).attr({id: 'OptionValue-' + id}); |
| 102 | $('td:eq(0)', nRow).wrapInner('<div style="margin-left: 10px;" class="crm-editable crmf-label" />'); |
| 103 | $('td:eq(0)', nRow).prepend('<div style="cursor:move; position: relative; left: -7px;" class="icon ui-icon-arrowthick-2-n-s" />'); |
| 104 | $('td:eq(2)', nRow).addClass('crmf-default_value'); |
| 105 | return nRow; |
| 106 | }, |
| 107 | "fnDrawCallback": function() { |
| 108 | // FIXME: trigger crmLoad and crmEditable would happen automatically |
| 109 | $('.crm-editable').crmEditable(); |
| 110 | }, |
| 111 | |
| 112 | "fnServerData": function ( sSource, aoData, fnCallback ) { |
| 113 | $.ajax( { |
| 114 | "dataType": 'json', |
| 115 | "type": "POST", |
| 116 | "url": sSource, |
| 117 | "data": aoData, |
| 118 | "success": fnCallback |
| 119 | } ); |
| 120 | } |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | var startPosition; |
| 126 | var endPosition; |
| 127 | var gid = {/literal}'{$optionGroupID}'{literal}; |
| 128 | |
| 129 | $("table.crm-option-selector tbody").sortable({ |
| 130 | handle: ".ui-icon-arrowthick-2-n-s", |
| 131 | cursor: "move", |
| 132 | start:function(event, ui) { |
| 133 | var oSettings = $('table.crm-option-selector').dataTable().fnSettings(); |
| 134 | var index = oSettings._iDisplayStart; |
| 135 | startPosition = index + ui.item.prevAll().length + 1; |
| 136 | }, |
| 137 | update: function(event, ui) { |
| 138 | var oSettings = $('table.crm-option-selector').dataTable().fnSettings(); |
| 139 | var index = oSettings._iDisplayStart; |
| 140 | endPosition = index + ui.item.prevAll().length + 1; |
| 141 | |
| 142 | CRM.status({}, $.getJSON(CRM.url('civicrm/ajax/reorder'), { |
| 143 | returnFormat:'JSON', |
| 144 | start:startPosition, |
| 145 | end: endPosition, |
| 146 | gid: gid |
| 147 | })) |
| 148 | .success(function() { |
| 149 | $("table.crm-option-selector tbody tr").each(function(i) { |
| 150 | $(this).removeClass('odd even').addClass(i % 2 ? 'even' : 'odd'); |
| 151 | }); |
| 152 | }); |
| 153 | } |
| 154 | }); |
| 155 | }); |
| 156 | |
| 157 | </script> |
| 158 | {/literal} |
| 159 | |
| 160 | <div class="action-link"> |
| 161 | {crmButton q="reset=1&action=add&fid=$fid&gid=$gid" class="action-item" icon="circle-plus"}{ts}Add Option{/ts}{/crmButton} |
| 162 | {crmButton p="civicrm/admin/custom/group/field" q="reset=1&action=browse&gid=$gid" class="action-item cancel" icon="close"}{ts}Done{/ts}{/crmButton} |
| 163 | </div> |
| 164 | </div> |
| 165 | </div> |
| 166 | {/if} |