Skip to content

Commit e010ad8

Browse files
committed
Add additional options to packet editor
1 parent 6f1b0f8 commit e010ad8

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

src/controllers/Packet/Edit.php

+26-18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function &run(Router &$router, View &$view, array &$args) {
3030
$model = new PacketEditModel();
3131
$model->csrf_id = mt_rand();
3232
$model->csrf_token = CSRF::generate($model->csrf_id, 7200); // 2 hours
33+
$model->deprecated = null;
3334
$model->error = null;
3435
$model->format = null;
3536
$model->id = null;
@@ -40,6 +41,7 @@ public function &run(Router &$router, View &$view, array &$args) {
4041
$model->products = Product::getAllProducts();
4142
$model->published = null;
4243
$model->remarks = null;
44+
$model->research = null;
4345
$model->used_by = null;
4446
$model->user = Authentication::$user;
4547

@@ -54,15 +56,15 @@ public function &run(Router &$router, View &$view, array &$args) {
5456
if ($model->packet === null) {
5557
$model->error = "NOT_FOUND";
5658
} else {
57-
$flags = $model->packet->getOptionsBitmask();
58-
59-
$model->id = $model->packet->getPacketId();
60-
$model->name = $model->packet->getPacketName();
61-
$model->format = $model->packet->getPacketFormat();
62-
$model->remarks = $model->packet->getPacketRemarks(false);
63-
$model->markdown = ($flags & Packet::OPTION_MARKDOWN);
64-
$model->published = ($flags & Packet::OPTION_PUBLISHED);
65-
$model->used_by = $this->getUsedBy($model->packet);
59+
$model->deprecated = $model->packet->isDeprecated();
60+
$model->id = $model->packet->getPacketId();
61+
$model->name = $model->packet->getPacketName();
62+
$model->format = $model->packet->getPacketFormat();
63+
$model->remarks = $model->packet->getPacketRemarks(false);
64+
$model->research = $model->packet->isInResearch();
65+
$model->markdown = $model->packet->isMarkdown();
66+
$model->published = $model->packet->isPublished();
67+
$model->used_by = $this->getUsedBy($model->packet);
6668

6769
if ($router->getRequestMethod() == "POST") {
6870
$this->handlePost($router, $model);
@@ -98,16 +100,20 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
98100
$remarks = (isset($data["remarks" ]) ? $data["remarks" ] : null);
99101
$markdown = (isset($data["markdown" ]) ? $data["markdown" ] : null);
100102
$content = (isset($data["content" ]) ? $data["content" ] : null);
101-
$publish = (isset($data["publish" ]) ? $data["publish" ] : null);
102-
$save = (isset($data["save" ]) ? $data["save" ] : null);
103+
$deprecated = (isset($data["deprecated"]) ? $data["deprecated"] : null);
104+
$research = (isset($data["research" ]) ? $data["research" ] : null);
105+
$published = (isset($data["published" ]) ? $data["published" ] : null);
103106
$used_by = (isset($data["used_by" ]) ? $data["used_by" ] : null);
104107

105-
$model->id = $id;
106-
$model->name = $name;
107-
$model->format = $format;
108-
$model->remarks = $remarks;
109-
$model->markdown = $markdown;
110-
$model->content = $content;
108+
$model->id = $id;
109+
$model->name = $name;
110+
$model->format = $format;
111+
$model->remarks = $remarks;
112+
$model->markdown = $markdown;
113+
$model->content = $content;
114+
$model->deprecated = $deprecated;
115+
$model->research = $research;
116+
$model->published = $published;
111117

112118
if (!$csrf_valid) {
113119
$model->error = "INVALID_CSRF";
@@ -132,7 +138,9 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
132138
$model->packet->setPacketFormat($model->format);
133139
$model->packet->setPacketRemarks($model->remarks);
134140
$model->packet->setMarkdown($model->markdown);
135-
$model->packet->setPublished($publish);
141+
$model->packet->setDeprecated($model->deprecated);
142+
$model->packet->setInResearch($model->research);
143+
$model->packet->setPublished($model->published);
136144

137145
$model->packet->setEditedCount(
138146
$model->packet->getEditedCount() + 1

src/libraries/Packet.php

+4
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ public function isInResearch() {
569569
return ($this->options_bitmask & self::OPTION_RESEARCH);
570570
}
571571

572+
public function isMarkdown() {
573+
return ($this->options_bitmask & self::OPTION_MARKDOWN);
574+
}
575+
572576
public function isPublished() {
573577
return ($this->options_bitmask & self::OPTION_PUBLISHED);
574578
}

src/templates/Packet/Edit.phtml

+15-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ switch ($this->getContext()->error) {
4040
$message = $this->getContext()->error;
4141
}
4242

43-
$tpl_markdown = ( $this->getContext()->markdown ? ' checked="checked"' : '' );
44-
4543
$this->additional_css[] = '/a/forms.css';
4644
require('./header.inc.phtml');
4745
?>
@@ -83,7 +81,7 @@ require('./header.inc.phtml');
8381
?></textarea>
8482
</section>
8583
<section>
86-
<label for="usedby">Used by:</label>
84+
<label>Used by:</label>
8785
<table>
8886
<thead></thead><tbody>
8987
<?php function add_product_checkbox( $id, $name, $checked ) { ?>
@@ -112,16 +110,27 @@ for ( $product_i = 0; $product_i < $product_ubound; ++$product_i ) { ?>
112110
<span style="float:right;">
113111
<label for="markdown" title="Use markdown or use raw HTML">Markdown</label>
114112
<input type="checkbox" name="markdown" id="markdown" tabindex="5"
115-
title="Use markdown or use raw HTML" value="1"<?php echo $tpl_markdown; ?>/>
113+
title="Use markdown or use raw HTML" value="1"<?=($this->getContext()->markdown?' checked="checked"':'')?>/>
116114
</span>
117115
<textarea name="remarks" id="remarks" tabindex="4" required
118116
style="height:200px;"><?php echo
119117
htmlspecialchars($this->getContext()->remarks, ENT_HTML5, "UTF-8");
120118
?></textarea>
121119
</section>
122120
<section>
123-
<input type="submit" name="publish" value="Publish" tabindex="6"/>
124-
<input type="submit" name="save" value="Unpublish" tabindex="7"/>
121+
<label>Flags:</label>
122+
<table>
123+
<thead></thead><tbody>
124+
<tr>
125+
<td><input type="checkbox" id="deprecated" name="deprecated" value="1"<?=($this->getContext()->deprecated?' checked="checked"':'')?> tabindex="6"/> <label for="deprecated">Deprecated</label></td>
126+
<td><input type="checkbox" id="research" name="research" value="1"<?=($this->getContext()->research?' checked="checked"':'')?> tabindex="7"/> <label for="research">In Research</label></td>
127+
<td><input type="checkbox" id="published" name="published" value="1"<?=($this->getContext()->published?' checked="checked"':'')?> tabindex="8"/> <label for="published">Published</label></td>
128+
</tr>
129+
</tbody>
130+
</table>
131+
</section>
132+
<section style="text-align:center;">
133+
<input type="submit" value="Save" tabindex="9"/>
125134
</section>
126135
</form>
127136
<?php } ?>

0 commit comments

Comments
 (0)