Przeglądaj źródła

Bug fix when select the type of the page

Diego Najar 6 lat temu
rodzic
commit
bf061d6fff

+ 3 - 3
bl-kernel/admin/views/content.php

@@ -85,7 +85,7 @@ function table($type) {
 					$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key();
 					echo '<td class="d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
 
-					echo '<td id="jscontentTools" class="pt-3 text-center d-none d-sm-table-cell w-25">'.PHP_EOL;
+					echo '<td class="contentTools pt-3 text-center d-sm-table-cell w-25">'.PHP_EOL;
 					echo '<a class="btn btn-outline-secondary btn-sm mb-1" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'"><span class="oi oi-pencil"></span> '.$L->g('Edit').'</a>'.PHP_EOL;
 					if (count($page->children())==0) {
 						echo '<button type="button" class="btn btn-outline-danger btn-sm deletePageButton mb-1" data-toggle="modal" data-target="#jsdeletePageModal" data-key="'.$page->key().'"><span class="oi oi-trash"></span> '.$L->g('Delete').'</button>'.PHP_EOL;
@@ -111,7 +111,7 @@ function table($type) {
 						$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$child->key() : '/'.$url->filters('page').'/'.$child->key();
 						echo '<td><a target="_blank" href="'.$child->permalink().'">'.$friendlyURL.'</a></td>';
 
-						echo '<td class="pt-3 text-center d-none d-sm-table-cell w-25">'.PHP_EOL;
+						echo '<td class="contentTools pt-3 text-center d-sm-table-cell w-25">'.PHP_EOL;
 						echo '<a class="btn btn-outline-secondary btn-sm mb-1" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$child->key().'"><span class="oi oi-pencil"></span> '.$L->g('Edit').'</a>'.PHP_EOL;
 						echo '<button type="button" class="btn btn-outline-danger btn-sm deletePageButton mb-1" data-toggle="modal" data-target="#jsdeletePageModal" data-key="'.$child->key().'"><span class="oi oi-trash"></span> '.$L->g('Delete').'</button>'.PHP_EOL;
 						echo '</td>';
@@ -143,7 +143,7 @@ function table($type) {
 				$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key();
 				echo '<td class="pt-3 d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
 
-				echo '<td id="jscontentTools" class="pt-3 text-center d-sm-table-cell w-25">'.PHP_EOL;
+				echo '<td class="contentTools pt-3 text-center d-sm-table-cell w-25">'.PHP_EOL;
 				echo '<a class="btn btn-outline-secondary btn-sm mb-1" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'"><span class="oi oi-pencil"></span> '.$L->g('Edit').'</a>'.PHP_EOL;
 				if (count($page->children())==0) {
 					echo '<button type="button" class="btn btn-outline-danger btn-sm deletePageButton mb-1" data-toggle="modal" data-target="#jsdeletePageModal" data-key="'.$page->key().'"><span class="oi oi-trash"></span> '.$L->g('Delete').'</button>'.PHP_EOL;

+ 7 - 16
bl-kernel/admin/views/edit-content.php

@@ -83,14 +83,6 @@ echo Bootstrap::formOpen(array(
 </div>
 <script>
 	$(document).ready(function() {
-		$("#jsPublishSwitch").on("click", function() {
-			$("#jstype").val("published");
-		});
-
-		$("#jsDraftSwitch").on("click", function() {
-			$("#jstype").val("draft");
-		});
-
 		$("#jsoptionsSidebar").on("click", function() {
 			$("#jseditorSidebar").toggle();
 			$("#jsshadow").toggle();
@@ -189,7 +181,7 @@ echo Bootstrap::formOpen(array(
 					'label'=>$L->g('Type'),
 					'selected'=>$page->type(),
 					'options'=>array(
-						'default'=>'- '.$L->g('Default').' -',
+						'published'=>'- '.$L->g('Default').' -',
 						'sticky'=>$L->g('Sticky'),
 						'static'=>$L->g('Static')
 					),
@@ -392,13 +384,12 @@ $(document).ready(function() {
 
 	// Button Save
 	$("#jsbuttonSave").on("click", function() {
-		// Get the type from the selector
-		var typeSelector = $("#jstypeSelector option:selected").val();
-		// Get the type from the switch
-		var typeSwitch = $("#jstype").val();
-		// Set the type from the selector if the switch is publish
-		if ((typeSelector!='default') && (typeSwitch=='published')) {
-			$("#jstype").val(typeSelector);
+		// If the switch is setted to "published", get the value from the selector
+		if ($("#jsPublishSwitch").is(':checked')) {
+			var value = $("#jstypeSelector option:selected").val();
+			$("#jstype").val(value);
+		} else {
+			$("#jstype").val("draft");
 		}
 
 		// Get the content

+ 7 - 16
bl-kernel/admin/views/new-content.php

@@ -69,14 +69,6 @@ echo Bootstrap::formOpen(array(
 </div>
 <script>
 	$(document).ready(function() {
-		$("#jsPublishSwitch").on("click", function() {
-			$("#jstype").val("published");
-		});
-
-		$("#jsDraftSwitch").on("click", function() {
-			$("#jstype").val("draft");
-		});
-
 		$("#jsoptionsSidebar").on("click", function() {
 			$("#jseditorSidebar").toggle();
 			$("#jsshadow").toggle();
@@ -167,7 +159,7 @@ echo Bootstrap::formOpen(array(
 					'label'=>$L->g('Type'),
 					'selected'=>'',
 					'options'=>array(
-						'default'=>'- '.$L->g('Default').' -',
+						'published'=>'- '.$L->g('Default').' -',
 						'sticky'=>$L->g('Sticky'),
 						'static'=>$L->g('Static')
 					),
@@ -338,13 +330,12 @@ $(document).ready(function() {
 
 	// Button Save
 	$("#jsbuttonSave").on("click", function() {
-		// Get the type from the selector
-		var typeSelector = $("#jstypeSelector option:selected").val();
-		// Get the type from the switch
-		var typeSwitch = $("#jstype").val();
-		// Set the type from the selector if the switch is publish
-		if ((typeSelector!='default') && (typeSwitch=='published')) {
-			$("#jstype").val(typeSelector);
+		// If the switch is setted to "published", get the value from the selector
+		if ($("#jsPublishSwitch").is(':checked')) {
+			var value = $("#jstypeSelector option:selected").val();
+			$("#jstype").val(value);
+		} else {
+			$("#jstype").val("draft");
 		}
 
 		// Get the content

+ 0 - 15
bl-kernel/functions.php

@@ -344,21 +344,6 @@ function editPage($args) {
 		return false;
 	}
 
-	// Title and content need to be here because from inside the dbPages is not visible
-	if (empty($args['title']) || empty($args['content'])) {
-		try {
-			$page = new Page($args['key']);
-			if (empty($args['title'])) {
-				$args['title'] = $page->title();
-			}
-			if (empty($args['content'])) {
-				$args['content'] = $page->contentRaw();
-			}
-		} catch (Exception $e) {
-			// continue
-		}
-	}
-
 	$key = $pages->edit($args);
 	if ($key) {
 		// Call the plugins after page modified

+ 3 - 3
bl-kernel/pages.class.php

@@ -197,8 +197,8 @@ class Pages extends dbJSON {
 		// This variable is not belong to the database so is not defined in $row
 		$newKey = $this->generateKey($slug, $parent, false, $key);
 
-		// If the page is draft then the created time is the current
-		if ($this->db[$key]['type']=='draft') {
+		// If the page is draft then the created date is the current
+		if ($row['type']=='draft') {
 			$row['date'] = Date::current(DB_DATE_FORMAT);
 		} elseif (!Valid::date($row['date'], DB_DATE_FORMAT)) {
 			$row['date'] = $this->db[$key]['date'];
@@ -227,7 +227,7 @@ class Pages extends dbJSON {
 		}
 
 		// Remove the old key
-		unset( $this->db[$key] );
+		unset ($this->db[$key]);
 
 		// Reindex Orphan Children
 		$this->reindexChildren($key, $newKey);