Skip to content

Commit

Permalink
Add flag for public notes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwins committed Sep 21, 2016
1 parent 965c783 commit 022a768
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
7 changes: 6 additions & 1 deletion api/txn-add-note.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
die_jsonp("No transaction specified.");

$note= $_REQUEST['note'];
$public= (int)$_REQUEST['public'];

if (!$note)
die_jsonp("No note given.");

$note= $db->escape($note);

$q= "INSERT INTO txn_note SET entered = NOW(), txn = $id, content = '$note'";
$q= "INSERT INTO txn_note
SET entered = NOW(),
txn = $id,
content = '$note',
public = $public";
$db->query($q)
or die_query($db, $q);

Expand Down
7 changes: 4 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ function (data) {
});
}

Txn.addNote= function(id, note) {
Txn.addNote= function(id, note, pub) {
$.getJSON("api/txn-add-note.php?callback=?",
{ id: id, note: note},
{ id: id, note: note, public: pub },
function (data) {
Txn.loadData(data);
});
Expand Down Expand Up @@ -1340,8 +1340,9 @@ function (data) {
dataModel.addNote= function(place, ev) {
var txn= Txn.id();
var note= $('input[name="note"]', place).val();
var pub= $('input[name="public"]', place).is(':checked') ? 1 : 0;

Txn.addNote(txn, note);
Txn.addNote(txn, note, pub);

$(place).closest('.modal').modal('hide');
}
Expand Down
9 changes: 5 additions & 4 deletions lib/txn.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,21 @@ function txn_load_payments($db, $id) {
}

function txn_load_notes($db, $id) {
$q= "SELECT id, entered, content
$q= "SELECT id, entered, content, public
FROM txn_note
WHERE txn = $id
ORDER BY entered ASC";

$r= $db->query($q)
or die_query($db, $q);

$payments= array();
$notes= array();
while ($row= $r->fetch_assoc()) {
$payments[]= $row;
$row['public']= (int)$row['public'];
$notes[]= $row;
}

return $payments;
return $notes;
}

function txn_apply_discounts($db, $id) {
Expand Down
1 change: 1 addition & 0 deletions scat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ CREATE TABLE `txn_note` (
`txn` int(10) unsigned NOT NULL,
`entered` datetime NOT NULL,
`content` text,
`public` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
Expand Down
10 changes: 9 additions & 1 deletion ui/show-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ <h4 class="modal-title">
<dl class="dl-horizontal">
<!-- ko foreach: notes -->
<dt data-bind="text: $data.entered"></dt>
<dd data-bind="text: $data.content"></dd>
<dd>
<span data-bind="visible: $data.public()"><i class="fa fa-comment" aria-hidden="true"></i></span>
<span data-bind="text: $data.content"></span>
</dd>
<!-- /ko -->
</dl>

Expand All @@ -32,6 +35,11 @@ <h4 class="modal-title">
</div>
</div>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="public" value="1"> Public?
</label>
</div>
</form>

</div>
Expand Down

0 comments on commit 022a768

Please sign in to comment.