<commit_before><? defined('C5_EXECUTE') or die("Access Denied."); ?>

<?

if (isset($entry)) { 

	$pk = PermissionKey::getByHandle('edit_page_properties');
	$pk->setPermissionObject($entry);
	$asl = $pk->getMyAssignment();
	$allowedAKIDs = $asl->getAttributesAllowedArray();

	$pk = PermissionKey::getByHandle('approve_page_versions');
	$pk->setPermissionObject($entry);
	$pa = $pk->getPermissionAccessObject();
	$workflow = (count($pa->getWorkflows()) > 0);

	?>

	<?=Loader::helper('concrete/dashboard')->getDashboardPaneHeaderWrapper(ucfirst($action) . ' ' . $ct->getCollectionTypeName(), false, false, false)?>
	<form method="post" class="form-horizontal" enctype="multipart/form-data" action="<?=$this->action('save')?>" id="ccm-dashboard-composer-form">
	<input type="hidden" name="ccm-publish-draft" value="0" />

	<div class="ccm-pane-body">
	

	<div id="composer-save-status"></div>
	
	<fieldset>
	<legend><?=t("Basic Information")?></legend>
	<? if ($asl->allowEditName()) { ?>
	<div class="control-group">
		<?=$form->label('cName', t('Name'))?>
		<div class="controls"><?=$form->text('cName', Loader::helper("text")->entities($name), array('class' => 'input-xlarge', 'onKeyUp' => "ccm_updateAddPageHandle()"))?></div>		
	</div>
	<? } ?>
	
	<? if ($asl->allowEditPaths()) { ?>
	<div class="control-group">
		<?=$form->label('cHandle', t('URL Slug'))?>
		<div class="controls"><?=$form->text('cHandle', $handle, array('class' => 'span3'))?>
		<img src="<?=ASSETS_URL_IMAGES?>/loader_intelligent_search.gif" width="43" height="11" id="ccm-url-slug-loader" style="display: none" />
		</div>		
	</div>
	<? } ?>

	<? if ($asl->allowEditDescription()) { ?>
	<div class="control-group">
		<?=$form->label('cDescription', t('Short Description'))?>
		<div class="controls"><?=$form->textarea('cDescription', Loader::helper("text")->entities($description), array('class' => 'input-xlarge', 'rows' => 5))?></div>		
	</div>
	<? } ?>

	<? if ($asl->allowEditDateTime()) { ?>
	<div class="control-group">
		<?=$form->label('cDatePublic', t('Date Posted'))?>
		<div class="controls"><? 
		if ($this->controller->isPost()) { 	
			$cDatePublic = Loader::helper('form/date_time')->translate('cDatePublic');
		}
		?><?=Loader::helper('form/date_time')->datetime('cDatePublic', $cDatePublic)?></div>		
	</div>
<? } ?>

	</fieldset>
	
	<? if ($entry->isComposerDraft()) { ?>
	<fieldset>
	<legend><?=t('Publish Location')?></legend>
	<div class="control-group">
		<span id="ccm-composer-publish-location"><?
		print $this->controller->getComposerDraftPublishText($entry);
		?>
		</span>
		
		<? 
	
	if ($ct->getCollectionTypeComposerPublishMethod() == 'PAGE_TYPE' || $ct->getCollectionTypeComposerPublishMethod() == 'CHOOSE') { ?>
		
		<a href="javascript:void(0)" onclick="ccm_openComposerPublishTargetWindow(false)"><?=t('Choose publish location.')?></a>
	
	<? } 
	
	?></div>
	</fieldset>
	<? } ?>
	
	<fieldset>
	<legend><?=t('Attributes &amp; Content')?></legend>
	<? 
	foreach($contentitems as $ci) {
		if ($ci instanceof AttributeKey) { 
			$ak = $ci;
			if (!in_array($ak->getAttributeKeyID(), $allowedAKIDs)) {
				continue;
			}
			
			if (is_object($entry)) {
				$value = $entry->getAttributeValueObject($ak);
			}
			?>
			<div class="control-group">
				<?=$ak->render('label');?>
				<div class="controls">
					<?=$ak->render('composer', $value, true)?>
				</div>
			</div>
		
		<? } else { 
			$b = $ci; 
			$b = $entry->getComposerBlockInstance($b);
			?>
		
		<div class="control-group">
		<?
		if (is_object($b)) {
			$bv = new BlockView();
			$bv->render($b, 'composer');
		} else {
			print t('Block not found. Unable to edit in composer.');
		}
		?>
		
		</div>
		
		<?
		} ?>
	<? }  ?>
	</fieldset>
	

	</div>
	<div class="ccm-pane-footer">
	<?
	$v = $entry->getVersionObject();
	
	?>
	

	<? if ($entry->isComposerDraft()) { 
	$pp = new Permissions($entry);
	?>
		<? if ($workflow) { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Submit to Workflow'), 'publish', 'right', 'primary')?>
		<? } else { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Publish Page'), 'publish', 'right', 'primary')?>
		<? } ?>
		<? if (PERMISSIONS_MODEL != 'simple' && $pp->canEditPagePermissions()) { ?>
			<?=Loader::helper('concrete/interface')->button_js(t('Permissions'), 'javascript:ccm_composerLaunchPermissions()', 'left', 'primary ccm-composer-hide-on-no-target')?>
		<? } ?>
	<? } else { ?>
		<? if ($workflow) { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Submit to Workflow'), 'publish', 'right', 'primary')?>
		<? } else { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Publish Changes'), 'publish', 'right', 'primary')?>
		<? } ?>
	<? } ?>

	<?=Loader::helper('concrete/interface')->button_js(t('Preview'), 'javascript:ccm_composerLaunchPreview()', 'right', 'ccm-composer-hide-on-approved')?>
	<?=Loader::helper('concrete/interface')->submit(t('Save'), 'save', 'right')?>
	<?=Loader::helper('concrete/interface')->submit(t('Discard'), 'discard', 'left', 'error ccm-composer-hide-on-approved')?>
	
	<?=$form->hidden('entryID', $entry->getCollectionID())?>
	<? if ($entry->isComposerDraft()) { ?>
		<input type="hidden" name="cPublishParentID" value="<?=$entry->getComposerDraftPublishParentID()?>" />
	<? } ?>
	<?=$form->hidden('autosave', 0)?>
	<?=Loader::helper('validation/token')->output('composer')?>
	</div>
	</form>
	<?=Loader::helper('concrete/dashboard')->getDashboardPaneFooterWrapper(false)?>


	<script type="text/javascript">
	var ccm_composerAutoSaveInterval = false;
	var ccm_composerDoAutoSaveAllowed = true;
	var ccm_composerAddPageTimer = false;

	ccm_updateAddPageHandle = function() {
		clearTimeout(ccm_composerAddPageTimer);
		ccm_composerAddPageTimer = setTimeout(function() {
			var val = $('#ccm-dashboard-composer-form input[name=cName]').val();
			$('#ccm-url-slug-loader').show();
			$.post('<?=REL_DIR_FILES_TOOLS_REQUIRED?>/pages/url_slug', {
				'token': '<?=Loader::helper('validation/token')->generate('get_url_slug')?>',
				'name': val,
				'parentID' : $("input[name=cPublishParentID]").val()
			}, function(r) {
				$('#ccm-url-slug-loader').hide();
				$('#ccm-dashboard-composer-form input[name=cHandle]').val(r);
			});
		}, 150);
	}<commit_msg>Improve ajax call to build composer page url slug<commit_after><? defined('C5_EXECUTE') or die("Access Denied."); ?>

<?

if (isset($entry)) { 

	$pk = PermissionKey::getByHandle('edit_page_properties');
	$pk->setPermissionObject($entry);
	$asl = $pk->getMyAssignment();
	$allowedAKIDs = $asl->getAttributesAllowedArray();

	$pk = PermissionKey::getByHandle('approve_page_versions');
	$pk->setPermissionObject($entry);
	$pa = $pk->getPermissionAccessObject();
	$workflow = (count($pa->getWorkflows()) > 0);

	?>

	<?=Loader::helper('concrete/dashboard')->getDashboardPaneHeaderWrapper(ucfirst($action) . ' ' . $ct->getCollectionTypeName(), false, false, false)?>
	<form method="post" class="form-horizontal" enctype="multipart/form-data" action="<?=$this->action('save')?>" id="ccm-dashboard-composer-form" onsubmit="if($('#ccm-url-slug-loader').is(':visible'))return false;jQuery.fn.dialog.showLoader()">
	<input type="hidden" name="ccm-publish-draft" value="0" />

	<div class="ccm-pane-body">
	

	<div id="composer-save-status"></div>
	
	<fieldset>
	<legend><?=t("Basic Information")?></legend>
	<? if ($asl->allowEditName()) { ?>
	<div class="control-group">
		<?=$form->label('cName', t('Name'))?>
		<div class="controls"><?=$form->text('cName', Loader::helper("text")->entities($name), array('class' => 'input-xlarge', 'onKeyUp' => "ccm_updateAddPageHandle()"))?></div>		
	</div>
	<? } ?>
	
	<? if ($asl->allowEditPaths()) { ?>
	<div class="control-group">
		<?=$form->label('cHandle', t('URL Slug'))?>
		<div class="controls"><?=$form->text('cHandle', $handle, array('class' => 'span3'))?>
		<img src="<?=ASSETS_URL_IMAGES?>/loader_intelligent_search.gif" width="43" height="11" id="ccm-url-slug-loader" style="display: none" />
		</div>		
	</div>
	<? } ?>

	<? if ($asl->allowEditDescription()) { ?>
	<div class="control-group">
		<?=$form->label('cDescription', t('Short Description'))?>
		<div class="controls"><?=$form->textarea('cDescription', Loader::helper("text")->entities($description), array('class' => 'input-xlarge', 'rows' => 5))?></div>		
	</div>
	<? } ?>

	<? if ($asl->allowEditDateTime()) { ?>
	<div class="control-group">
		<?=$form->label('cDatePublic', t('Date Posted'))?>
		<div class="controls"><? 
		if ($this->controller->isPost()) { 	
			$cDatePublic = Loader::helper('form/date_time')->translate('cDatePublic');
		}
		?><?=Loader::helper('form/date_time')->datetime('cDatePublic', $cDatePublic)?></div>		
	</div>
<? } ?>

	</fieldset>
	
	<? if ($entry->isComposerDraft()) { ?>
	<fieldset>
	<legend><?=t('Publish Location')?></legend>
	<div class="control-group">
		<span id="ccm-composer-publish-location"><?
		print $this->controller->getComposerDraftPublishText($entry);
		?>
		</span>
		
		<? 
	
	if ($ct->getCollectionTypeComposerPublishMethod() == 'PAGE_TYPE' || $ct->getCollectionTypeComposerPublishMethod() == 'CHOOSE') { ?>
		
		<a href="javascript:void(0)" onclick="ccm_openComposerPublishTargetWindow(false)"><?=t('Choose publish location.')?></a>
	
	<? } 
	
	?></div>
	</fieldset>
	<? } ?>
	
	<fieldset>
	<legend><?=t('Attributes &amp; Content')?></legend>
	<? 
	foreach($contentitems as $ci) {
		if ($ci instanceof AttributeKey) { 
			$ak = $ci;
			if (!in_array($ak->getAttributeKeyID(), $allowedAKIDs)) {
				continue;
			}
			
			if (is_object($entry)) {
				$value = $entry->getAttributeValueObject($ak);
			}
			?>
			<div class="control-group">
				<?=$ak->render('label');?>
				<div class="controls">
					<?=$ak->render('composer', $value, true)?>
				</div>
			</div>
		
		<? } else { 
			$b = $ci; 
			$b = $entry->getComposerBlockInstance($b);
			?>
		
		<div class="control-group">
		<?
		if (is_object($b)) {
			$bv = new BlockView();
			$bv->render($b, 'composer');
		} else {
			print t('Block not found. Unable to edit in composer.');
		}
		?>
		
		</div>
		
		<?
		} ?>
	<? }  ?>
	</fieldset>
	

	</div>
	<div class="ccm-pane-footer">
	<?
	$v = $entry->getVersionObject();
	
	?>
	

	<? if ($entry->isComposerDraft()) { 
	$pp = new Permissions($entry);
	?>
		<? if ($workflow) { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Submit to Workflow'), 'publish', 'right', 'primary')?>
		<? } else { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Publish Page'), 'publish', 'right', 'primary')?>
		<? } ?>
		<? if (PERMISSIONS_MODEL != 'simple' && $pp->canEditPagePermissions()) { ?>
			<?=Loader::helper('concrete/interface')->button_js(t('Permissions'), 'javascript:ccm_composerLaunchPermissions()', 'left', 'primary ccm-composer-hide-on-no-target')?>
		<? } ?>
	<? } else { ?>
		<? if ($workflow) { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Submit to Workflow'), 'publish', 'right', 'primary')?>
		<? } else { ?>
			<?=Loader::helper('concrete/interface')->submit(t('Publish Changes'), 'publish', 'right', 'primary')?>
		<? } ?>
	<? } ?>

	<?=Loader::helper('concrete/interface')->button_js(t('Preview'), 'javascript:ccm_composerLaunchPreview()', 'right', 'ccm-composer-hide-on-approved')?>
	<?=Loader::helper('concrete/interface')->submit(t('Save'), 'save', 'right')?>
	<?=Loader::helper('concrete/interface')->submit(t('Discard'), 'discard', 'left', 'error ccm-composer-hide-on-approved')?>
	
	<?=$form->hidden('entryID', $entry->getCollectionID())?>
	<? if ($entry->isComposerDraft()) { ?>
		<input type="hidden" name="cPublishParentID" value="<?=$entry->getComposerDraftPublishParentID()?>" />
	<? } ?>
	<?=$form->hidden('autosave', 0)?>
	<?=Loader::helper('validation/token')->output('composer')?>
	</div>
	</form>
	<?=Loader::helper('concrete/dashboard')->getDashboardPaneFooterWrapper(false)?>


	<script type="text/javascript">
	var ccm_composerAutoSaveInterval = false;
	var ccm_composerDoAutoSaveAllowed = true;

	ccm_updateAddPageHandle = function() {
		if(ccm_updateAddPageHandle.lastRequested === $.trim($('#ccm-dashboard-composer-form input[name=cName]').val())) {
			return;
		}
		if(ccm_updateAddPageHandle.timer) {
			clearTimeout(ccm_updateAddPageHandle.timer);
		}
		ccm_updateAddPageHandle.timer = setTimeout(function() {
			var val = $.trim($('#ccm-dashboard-composer-form input[name=cName]').val());
			ccm_updateAddPageHandle.lastRequested = val;
			delete ccm_updateAddPageHandle.timer;
			$('#ccm-url-slug-loader').show();
			ccm_updateAddPageHandle.xhr = $.ajax({
				type: 'POST',
				url: '<?=REL_DIR_FILES_TOOLS_REQUIRED?>/pages/url_slug',
				data: {
					'token': '<?=Loader::helper('validation/token')->generate('get_url_slug')?>',
					'name': val,
					'parentID' : $("input[name=cPublishParentID]").val()
				}
			})
			.done(function(r, textStatus, xhr) {
				if(ccm_updateAddPageHandle.xhr == xhr) {
					$('#ccm-dashboard-composer-form input[name=cHandle]').val(r);
					$('#ccm-url-slug-loader').hide();
				}
			})
			.fail(function(xhr) {
				if(ccm_updateAddPageHandle.xhr == xhr) {
					$('#ccm-url-slug-loader').hide();
				}
			});
		}, 150);
	};
{'fraction_non_alphanumeric': 0.24323500266788628, 'fraction_numerical': 0.0021343090174555986, 'mean_word_length': 5.218009478672986, 'pattern_counts': {'":': 0, '<': 241, '<?xml version=': 0, '>': 365, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2887659', 'n_tokens_mistral': 5082, 'n_tokens_neox': 4680, 'n_words': 628}