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();
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_start();
@ -22,7 +31,7 @@ $tiles = $database->select("tiles", ["tileid", "page", "styleid", "content", "wi
foreach ($styles as $style) {
?>
.tile-style-<?php echo $style["styleid"]; ?> {
<?php echo $style["css"] . "\n"; ?>
<?php echo $style["css"] . "\n"; ?>
}
<?php
}
@ -44,12 +53,13 @@ foreach ($tiles as $tile) {
<?php
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
if (defined("EDIT_MODE") && EDIT_MODE == true) {
?><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 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>
<?php } ?>
<div id="tile-<?php echo $tile["tileid"]; ?>-content" class="tile-style-<?php echo $tile["styleid"]; ?>">
@ -66,11 +76,25 @@ foreach ($tiles as $tile) {
<?php
$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"
. "<meta charset=\"utf-8\">\n"
. "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
. "<title></title>\n"
. "<style nonce=\"$SECURE_NONCE\">$contentcss</style>\n"
. "$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 {
?>
<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 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 class="pages-box">

@ -9,7 +9,7 @@ $pubdata = [
'styleid' => '',
'columns' => '',
'permid' => ''
];
];
$editing = false;
$cloning = false;
@ -21,8 +21,7 @@ if (!is_empty($VARS['id'])) {
$cloning = true;
}
$pubdata = $database->select(
'publications',
[
'publications', [
'pubname (name)',
'pubdate',
'styleid',
@ -118,6 +117,7 @@ if (!is_empty($VARS['id'])) {
<div class="panel-footer">
<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
if ($editing && !$cloning) {
?>

@ -3,15 +3,43 @@ $("#new_tile_btn").click(function () {
});
$(".edit-btn").click(function () {
var tileid = $(this).data("tile");
$("#tile-" + tileid + "-content .tile-html").summernote({
focus: true
});
var tileid = $(this).data("tile");
$("#tile-" + tileid + "-content .tile-html").summernote({
focus: true
});
});
$(".save-btn").click(function () {
var tileid = $(this).data("tile");
saveTile(tileid);
var tileid = $(this).data("tile");
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) {
@ -21,6 +49,13 @@ function saveTile(tileid) {
var styleid = tile.data("styleid");
var width = tile.data("width");
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", {
action: "savetile",
tileid: tileid,
@ -29,9 +64,7 @@ function saveTile(tileid) {
styleid: styleid,
width: width,
order: order,
content: tile_content.summernote("code")
}, function (d) {
tile_content.summernote("destroy");
content: content
});
}
Loading…
Cancel
Save