示例#1
0
/** 
* Manage Custom Fields
* 
* @return void
*/
function show_custom_fields()
{
    $CustomFields = new CustomFields();
    $customFields = $CustomFields->getCustomFields();
    ?>
	<style> .hidden_main {display:none;} </style>
	<h3 class="floated"><?php 
    echo i18n_r(BLOGFILE . '/MANAGE') . ' ' . i18n_r(BLOGFILE . '/CUSTOM_FIELDS');
    ?>
</h3>
	<p class="clear">
		<?php 
    i18n(BLOGFILE . '/CUSTOMFIELDS_DESCR');
    ?>
	</p>

	<form method="post" id="customfieldsForm">
	 	<h3 style="font-size:15px;">
	 		<?php 
    i18n(BLOGFILE . '/CUSTOM_FIELDS_OPTIONS_AREA');
    ?>
	 		<br /> 
	 		<span style="font-size:12px;color:#666;"><?php 
    i18n(BLOGFILE . '/OPTIONS_AREA_DESCRP');
    ?>
</span>
	 	</h3>
		<table id="editfields" class="edittable highlight options_cf">
			<thead>
				<tr>
					<th><?php 
    i18n(BLOGFILE . '/NAME');
    ?>
</th>
					<th><?php 
    i18n(BLOGFILE . '/LABEL');
    ?>
</th>
					<th style="width:100px;"><?php 
    i18n(BLOGFILE . '/TYPE');
    ?>
</th>
					<th><?php 
    i18n(BLOGFILE . '/DEFAULT_VALUE');
    ?>
</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<?php 
    $count_options = 0;
    if (!empty($customFields['options'])) {
        foreach ($customFields['options'] as $customOptionsField) {
            get_blog_custom_fields_list('sortable', $count_options, $customOptionsField, 'options');
            $count_options++;
        }
    }
    get_blog_custom_fields_list('hidden', $count_options, null, 'options');
    ?>
				<tr>
					<td colspan="4"><a href="#" class="add_field">
						<?php 
    i18n(BLOGFILE . '/ADD');
    ?>
</a>
					</td>
					<td class="secondarylink">
						<a href="#" class="add_field" title="<?php 
    i18n(BLOGFILE . '/ADD');
    ?>
">+</a>
					</td>
				</tr>
			</tbody>
		</table>
	 	<h3 style="font-size:15px;">
	 		<?php 
    i18n(BLOGFILE . '/CUSTOM_FIELDS_MAIN_AREA');
    ?>
	 		<br />
	 		<span style="font-size:12px;color:#666;"><?php 
    i18n(BLOGFILE . '/MAIN_AREA_DESCRP');
    ?>
</span>
	 	</h3>
		<table id="editfields" class="edittable highlight main_cf">
			<thead>
				<tr>
					<th><?php 
    i18n(BLOGFILE . '/NAME');
    ?>
</th>
					<th><?php 
    i18n(BLOGFILE . '/LABEL');
    ?>
</th>
					<th style="width:100px;"><?php 
    i18n(BLOGFILE . '/TYPE');
    ?>
</th>
					<th><?php 
    i18n(BLOGFILE . '/DEFAULT_VALUE');
    ?>
</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
	 				<?php 
    $count_main = 0;
    if (!empty($customFields['main'])) {
        foreach ($customFields['main'] as $customMainField) {
            get_blog_custom_fields_list('sortable', $count_main, $customMainField, 'main');
            $count_main++;
        }
    }
    get_blog_custom_fields_list('hidden_main', $count_main, null, 'main');
    ?>
				<tr>
					<td colspan="4"><a href="#" class="add_main_field">
						<?php 
    i18n(BLOGFILE . '/ADD');
    ?>
</a>
					</td>
					<td class="secondarylink">
						<a href="#" class="add_main_field" title="<?php 
    i18n(BLOGFILE . '/ADD');
    ?>
">+</a>
					</td>
				</tr>
			</tbody>
		</table>
	  	<input type="submit" name="save_custom_fields" value="<?php 
    i18n(BLOGFILE . '/SAVE');
    ?>
" class="submit"/>
	</form>
	<script type="text/javascript" src="../plugins/blog/js/jquery-ui.sort.min.js"></script>
	<script>
		function renumberCustomFields() {
			$('.options_cf tbody tr').each(function(i,tr) {
				$(tr).find('input, select, textarea').each(function(k,elem) {
					var name = $(elem).attr('name').replace(/_\d+_/, '_'+(i)+'_');
					$(elem).attr('name', name);
				});
			});
		}
		function renumberMainCustomFields() {
			$('.main_cf tbody tr').each(function(i,tr) {
				$(tr).find('input, select, textarea').each(function(k,elem) {
					var name = $(elem).attr('name').replace(/_\d+_/, '_'+(i)+'_');
					$(elem).attr('name', name);
				});
			});
		}
		$(function() {
		    $('select[name$=_type]').change(function(e) {
		      var val = $(e.target).val();
		      var $ta = $(e.target).closest('td').find('textarea');
		      if (val == 'dropdown') $ta.css('display','inline'); else $ta.css('display','none');
		    });
		    $('a.delete_options').click(function(e) {
		      $(e.target).closest('tr').remove();
		      renumberCustomFields();
		    });
		    $('a.delete_main').click(function(e) {
		      $(e.target).closest('tr').remove();
		      renumberMainCustomFields();
		    });
			$('a.add_field').click(function(e) {
				var $tr = $(e.target).closest('tbody').find('tr.hidden');
				$tr.before($tr.clone(true).removeClass('hidden').addClass('sortable'));
				renumberCustomFields();
			});
			$('a.add_main_field').click(function(e) {
				var $tr = $(e.target).closest('tbody').find('tr.hidden_main');
				$tr.before($tr.clone(true).removeClass('hidden_main').addClass('sortable'));
				renumberMainCustomFields();
			});
			$('#customfieldsForm .main_cf tbody').sortable({
				items:"tr.sortable", handle:'td',
				update:function(e,ui) { renumberMainCustomFields(); }
			});
			$('#customfieldsForm .options_cf tbody').sortable({
				items:"tr.sortable", handle:'td',
				update:function(e,ui) { renumberCustomFields(); }
			});
			renumberCustomFields();
			renumberMainCustomFields();
		});
	</script>
<?php 
}