Add tile metadata editing and preview button (see #2)

master
Skylar Ittner 7 years ago
parent 479a2cc30b
commit 5aff506911

@ -3,7 +3,16 @@ require_once __DIR__ . "/../required.php";
dieifnotloggedin(); dieifnotloggedin();
if (!defined("IN_NEWSPEN")) { if (!defined("IN_NEWSPEN")) {
die("Please don't do that."); if (is_numeric($VARS['pubid'])) {
if ($database->has('publications', ['pubid' => $VARS['pubid']])) {
$pub = $VARS['pubid'];
$pubdata = $database->get("publications", ["pubname", "pubdate", "styleid", "columns"], ["pubid" => $pub]);
} else {
die(lang("invalid parameters", false));
}
} else {
die(lang("invalid parameters", false));
}
} }
ob_end_flush(); ob_end_flush();
ob_start(); ob_start();
@ -22,7 +31,7 @@ $tiles = $database->select("tiles", ["tileid", "page", "styleid", "content", "wi
foreach ($styles as $style) { foreach ($styles as $style) {
?> ?>
.tile-style-<?php echo $style["styleid"]; ?> { .tile-style-<?php echo $style["styleid"]; ?> {
<?php echo $style["css"] . "\n"; ?> <?php echo $style["css"] . "\n"; ?>
} }
<?php <?php
} }
@ -44,12 +53,13 @@ foreach ($tiles as $tile) {
<?php <?php
foreach ($tiles as $tile) { foreach ($tiles as $tile) {
?> ?>
<div class="tile" id="tile-<?php echo $tile["tileid"]; ?>" data-tileid="<?php echo $tile["tileid"]; ?>" data-styleid="<?php echo $tile["styleid"]; ?>" data-page="<?php echo $tile["page"]; ?>" data-styleid="<?php echo $tile["styleid"]; ?>" data-width="<?php echo $tile["width"]; ?>" data-order="<?php echo $tile["order"]; ?>"> <div class="tile" id="tile-<?php echo $tile["tileid"]; ?>" data-tileid="<?php echo $tile["tileid"]; ?>" data-page="<?php echo $tile["page"]; ?>" data-styleid="<?php echo $tile["styleid"]; ?>" data-width="<?php echo $tile["width"]; ?>" data-order="<?php echo $tile["order"]; ?>">
<?php <?php
if (defined("EDIT_MODE") && EDIT_MODE == true) { if (defined("EDIT_MODE") && EDIT_MODE == true) {
?><div class="btn-group btn-group-sm"> ?><div class="btn-group btn-group-sm">
<button type="button" class="btn btn-default edit-btn" data-tile="<?php echo $tile["tileid"]; ?>"><i class="fa fa-pencil"></i> <?php lang("edit"); ?></button> <button type="button" class="btn btn-default edit-btn" data-tile="<?php echo $tile["tileid"]; ?>"><i class="fa fa-pencil"></i> <?php lang("edit"); ?></button>
<button type="button" class="btn btn-default save-btn" data-tile="<?php echo $tile["tileid"]; ?>"><i class="fa fa-save"></i> <?php lang("save"); ?></button> <button type="button" class="btn btn-default save-btn" data-tile="<?php echo $tile["tileid"]; ?>"><i class="fa fa-save"></i> <?php lang("save"); ?></button>
<button type="button" class="btn btn-default opts-btn" data-tile="<?php echo $tile["tileid"]; ?>" data-toggle="modal" data-target="#tile-options-modal"><i class="fa fa-gear"></i> <?php lang("options"); ?></button>
</div> </div>
<?php } ?> <?php } ?>
<div id="tile-<?php echo $tile["tileid"]; ?>-content" class="tile-style-<?php echo $tile["styleid"]; ?>"> <div id="tile-<?php echo $tile["tileid"]; ?>-content" class="tile-style-<?php echo $tile["styleid"]; ?>">
@ -66,11 +76,25 @@ foreach ($tiles as $tile) {
<?php <?php
$content = ob_get_clean(); $content = ob_get_clean();
if (defined("HTML_ME")) { if (defined("HTML_ME") || !defined("IN_NEWSPEN")) {
$contentcss = file_get_contents(__DIR__ . "/../static/css/content.css");
$content = "<!DOCTYPE html>\n" $content = "<!DOCTYPE html>\n"
. "<meta charset=\"utf-8\">\n" . "<meta charset=\"utf-8\">\n"
. "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" . "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
. "<title></title>\n" . "<title></title>\n"
. "<style nonce=\"$SECURE_NONCE\">$contentcss</style>\n"
. "$content"; . "$content";
// Credit: https://stackoverflow.com/a/709684
$content = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $content);
// End credit
$content = str_replace("\t", " ", $content);
// TODO: replace this loop with something less freshman
while (strpos($content, " ") !== FALSE) {
$content = str_replace(" ", " ", $content);
}
}
if (!defined("IN_NEWSPEN")) {
echo $content;
} }
?> ?>

@ -40,8 +40,47 @@ if ($pub === false) {
} else { } else {
?> ?>
<div class="modal fade" id="tile-options-modal" tabindex="-1" role="dialog" aria-labelledby="tile-options-title">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="tile-options-title"><?php lang("edit tile"); ?></h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="width" class="control-label"><i class="fa fa-text-width"></i> <?php lang("width"); ?></label>
<input type="number" class="form-control" id="width">
</div>
<div class="form-group">
<label for="order" class="control-label"><i class="fa fa-sort"></i> <?php lang("order"); ?></label>
<input type="number" class="form-control" id="order">
</div>
<div class="form-group">
<label for="style" class="control-label"><i class="fa fa-star"></i> <?php lang("style"); ?></label>
<select id="style" class="form-control">
<?php
$styles = $database->select("tile_styles", ['styleid', 'stylename']);
foreach ($styles as $s) {
$si = $s['styleid'];
$sn = $s['stylename'];
echo "<option value=\"$si\">$sn</option>\n";
}
?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php lang("close"); ?></button>
<button type="button" class="btn btn-primary" id="modal-save-btn" data-tile=""><?php lang("save"); ?></button>
</div>
</div>
</div>
</div>
<div class="btn-group mgn-btm-10px"> <div class="btn-group mgn-btm-10px">
<div class="btn btn-success" id="new_tile_btn"><i class="fa fa-plus"></i> <?php lang("new tile"); ?></div> <div class="btn btn-success" id="new_tile_btn"><i class="fa fa-plus"></i> <?php lang("new tile"); ?></div>
<a class="btn btn-primary" id="preview_btn" href="lib/gencontent.php?pubid=1" target="_BLANK"><i class="fa fa-search"></i> <?php lang("preview"); ?></a>
</div> </div>
<div class="pages-box"> <div class="pages-box">

@ -9,7 +9,7 @@ $pubdata = [
'styleid' => '', 'styleid' => '',
'columns' => '', 'columns' => '',
'permid' => '' 'permid' => ''
]; ];
$editing = false; $editing = false;
$cloning = false; $cloning = false;
@ -21,8 +21,7 @@ if (!is_empty($VARS['id'])) {
$cloning = true; $cloning = true;
} }
$pubdata = $database->select( $pubdata = $database->select(
'publications', 'publications', [
[
'pubname (name)', 'pubname (name)',
'pubdate', 'pubdate',
'styleid', 'styleid',
@ -118,6 +117,7 @@ if (!is_empty($VARS['id'])) {
<div class="panel-footer"> <div class="panel-footer">
<button type="submit" class="btn btn-success"><i class="fa fa-floppy-o"></i> <?php lang("save"); ?></button> <button type="submit" class="btn btn-success"><i class="fa fa-floppy-o"></i> <?php lang("save"); ?></button>
&nbsp; <a href="app.php?page=content&pubid=<?php echo htmlspecialchars($VARS['id']); ?>" class="btn btn-primary"><i class="fa fa-pencil"></i> <?php lang('edit content'); ?></a>
<?php <?php
if ($editing && !$cloning) { if ($editing && !$cloning) {
?> ?>

@ -3,15 +3,43 @@ $("#new_tile_btn").click(function () {
}); });
$(".edit-btn").click(function () { $(".edit-btn").click(function () {
var tileid = $(this).data("tile"); var tileid = $(this).data("tile");
$("#tile-" + tileid + "-content .tile-html").summernote({ $("#tile-" + tileid + "-content .tile-html").summernote({
focus: true focus: true
}); });
}); });
$(".save-btn").click(function () { $(".save-btn").click(function () {
var tileid = $(this).data("tile"); var tileid = $(this).data("tile");
saveTile(tileid); saveTile(tileid);
});
$("#modal-save-btn").click(function () {
var tileid = $("#modal-save-btn").data("tile");
var oldstyle = $("#tile-" + tileid).data("styleid");
var newstyle = $("#style").val();
var width = $("#width").val();
var order = $("#order").val();
$("#tile-" + tileid).data("styleid", newstyle);
$("#tile-" + tileid + "-content").removeClass("tile-style-" + oldstyle);
$("#tile-" + tileid + "-content").addClass("tile-style-" + newstyle);
$("#tile-" + tileid).data("width", width);
$("#tile-" + tileid).css("width", width);
$("#tile-" + tileid).data("order", order);
$("#tile-" + tileid).css("order", order);
saveTile(tileid);
$("#tile-options-modal").modal('hide');
});
$('#tile-options-modal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var tileid = button.data('tile');
var tile = $("#tile-" + tileid);
var modal = $(this);
modal.find('#width').val(tile.data("width"));
modal.find('#order').val(tile.data("order"));
modal.find('#style').val(tile.data("styleid"));
modal.find('#modal-save-btn').data("tile", tileid);
}); });
function saveTile(tileid) { function saveTile(tileid) {
@ -21,6 +49,13 @@ function saveTile(tileid) {
var styleid = tile.data("styleid"); var styleid = tile.data("styleid");
var width = tile.data("width"); var width = tile.data("width");
var order = tile.data("order"); var order = tile.data("order");
var content = "";
if (tile_content.css("display") == "none") {
content = tile_content.summernote("code");
tile_content.summernote("destroy");
} else {
content = tile_content.html();
}
$.post("action.php", { $.post("action.php", {
action: "savetile", action: "savetile",
tileid: tileid, tileid: tileid,
@ -29,9 +64,7 @@ function saveTile(tileid) {
styleid: styleid, styleid: styleid,
width: width, width: width,
order: order, order: order,
content: tile_content.summernote("code") content: content
}, function (d) {
tile_content.summernote("destroy");
}); });
} }
Loading…
Cancel
Save