Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make page name in list editable

  • Loading branch information...
commit ec7c47959a310e91552d6b903f39f7ff509ee8eb 1 parent 21303c5
@thomaspark authored
Showing with 56 additions and 7 deletions.
  1. +10 −1 app.php
  2. +31 −6 list-home-code.php
  3. +15 −0 update.php
View
11 app.php
@@ -196,12 +196,14 @@
if (!$code_id) {
$code_id = generateCodeId();
$revision = 1;
+ $custom_name = $code_id;
} else {
$revision = getMaxRevision($code_id);
+ $custom_name = getCustomName($code_id, $revision);
$revision++;
}
- $sql = sprintf('insert into sandbox (javascript, html, created, last_viewed, url, revision) values ("%s", "%s", now(), now(), "%s", "%s")', mysql_real_escape_string($javascript), mysql_real_escape_string($html), mysql_real_escape_string($code_id), mysql_real_escape_string($revision));
+ $sql = sprintf('insert into sandbox (javascript, html, created, last_viewed, url, revision, customname) values ("%s", "%s", now(), now(), "%s", "%s", "%s")', mysql_real_escape_string($javascript), mysql_real_escape_string($html), mysql_real_escape_string($code_id), mysql_real_escape_string($revision), mysql_real_escape_string($custom_name));
// a few simple tests to pass before we save
if (($html == '' && $html == $javascript)) {
@@ -389,6 +391,13 @@ function getMaxRevision($code_id) {
return $row->rev ? $row->rev : 0;
}
+function getCustomName($code_id, $revision) {
+ $sql = sprintf('select customname from sandbox where url="%s" and revision="%s"', mysql_real_escape_string($code_id), mysql_real_escape_string($revision));
+ $result = mysql_query($sql);
+ $row = mysql_fetch_object($result);
+ return $row->customname ? $row->customname : "";
+}
+
function formatCompletedCode($html, $javascript, $code_id, $revision) {
global $ajax, $quiet;
View
37 list-home-code.php
@@ -142,13 +142,14 @@ function getRelativeTime($date) {
#bins .url {
text-align: right;
- width: 25%;
+ width: 35%;
padding-left: 20px;
padding-right: 20px;
}
-#bins .url a {
+#bins .url .revision {
color: #0097fe;
+ visibility: visible;
}
#bins .url a span {
@@ -160,6 +161,11 @@ function getRelativeTime($date) {
visibility: visible;
}
+#bins .rename {
+ cursor: pointer;
+ color: #ddd !important;
+}
+
#bins .created {
width: 25%;
}
@@ -177,7 +183,8 @@ function getRelativeTime($date) {
#bins tr:hover *,
#bins tr.hover *,
#bins tr:hover span,
-#bins tr.hover span {
+#bins tr.hover span,
+#bins tr.hover span.revision {
background: #0097fe;
color: #fff;
/*cursor: pointer;*/
@@ -224,9 +231,25 @@ function getRelativeTime($date) {
$('.rename').hide();
$('.rename').click(function(){
- var currentName = $(this).parent().parent().attr('data-url').slice(0, -1);
+ var currentName = $(this).siblings('a').children('.first').text();
var newName = prompt('What would you like to name this page?', currentName);
- if (newName) {
+
+ if ((newName) && (newName !== currentName)) {
+ var url = $(this).parent().parent().attr('id');
+ var revision = $(this).siblings('a').children('.revision').text();
+ var maxLength = 22;
+
+ $.post("update.php", {
+ customName: newName,
+ url: url,
+ revision: revision
+ });
+
+ if (newName.length > maxLength+1) {
+ $(this).siblings('a').children('span.first').html(newName.substr(0, maxLength) + '…');
+ } else {
+ $(this).siblings('a').children('span.first').html(newName);
+ }
}
@@ -267,6 +290,8 @@ function getRelativeTime($date) {
foreach ($bins[$key] as $bin) {
$code = $bin['url'];
$revision = $bin['revision'];
+ $customName = $bin['customname'];
+
$url = formatURL($bin['url'], $bin['revision']);
preg_match('/<title>(.*?)<\/title>/', $bin['html'], $match);
preg_match('/<body.*?>(.*)/s', $bin['html'], $body);
@@ -292,7 +317,7 @@ function getRelativeTime($date) {
<tr data-type="spacer"><td colspan=3></td></tr>
<?php endif ?>
<tr data-url="<?=$url?>" <?=($firstTime ? ' class="parent" id="' : ' class="child ') . $code . '">' ?>
- <td class="url"><?=($firstTime) ? '<span class="rename">Rename</span> ': ''?><?=($firstTime && $revision > 1) ? '<span class="action">▶</span> ': '<span class="inaction">&nbsp;</span>'?> <a href="<?=$url?>edit"><span<?=($firstTime ? ' class="first"' : '') . '>' . $bin['url']?></span> <?=$bin['revision']?></a></td>
+ <td class="url"><?=($firstTime) ? '<span class="rename">Rename</span> ': ''?><?=($firstTime && $revision > 1) ? '<span class="action">▶</span> ': '<span class="inaction">&nbsp;</span>'?> <a href="<?=$url?>edit"><span<?=($firstTime ? ' class="first"' : '') . '>' . ($bin['customname'] ? $bin['customname'] : $bin['url']) ?></span> <span class="revision"><?=$bin['revision']?></span></a></td>
<td class="created"><a pubdate="<?=$bin['created']?>" href="<?=$url?>edit"><?=getRelativeTime($bin['created'])?></a></td>
<td class="title"><a href="<?=$url?>edit"><?=substr($title, 0, 200)?></a></td>
</tr>
View
15 update.php
@@ -0,0 +1,15 @@
+<?php
+
+ include('config.php'); // contains DB & important versioning
+
+ $custom_name = $_POST['customName'];
+ $url = $_POST['url'];
+ $revision = $_POST['revision'];
+
+ $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
+ mysql_select_db(DB_NAME, $link);
+
+ $sql = sprintf('update sandbox set customname="%s" where url="%s" and revision="%s"', mysql_real_escape_string($custom_name), mysql_real_escape_string($url), mysql_real_escape_string($revision));
+ mysql_query($sql);
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.