implement poll UI in jot

This commit is contained in:
Mario 2020-02-27 05:48:28 +01:00 committed by Zot
parent 56d97a876d
commit 72bdd7963f
6 changed files with 131 additions and 16 deletions

View file

@ -384,6 +384,7 @@ class Item extends Controller {
$consensus = intval($_REQUEST['consensus']);
$nocomment = intval($_REQUEST['nocomment']);
$is_poll = ((trim($_REQUEST['poll_answers'][0]) != '' && trim($_REQUEST['poll_answers'][1]) != '') ? true : false);
// 'origin' (if non-zero) indicates that this network is where the message originated,
// for the purpose of relaying comments to other conversation members.
@ -1101,7 +1102,21 @@ class Item extends Controller {
}
}
$obj = $this->extract_poll_data($body,[ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]);
if($is_poll) {
$poll = [
'question' => $body,
'answers' => $_REQUEST['poll_answers'],
'multiple_answers' => $_REQUEST['poll_multiple_answers'],
'expire_value' => $_REQUEST['poll_expire_value'],
'expire_unit' => $_REQUEST['poll_expire_unit']
];
$obj = $this->extract_poll_data($poll, [ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]);
}
else {
$obj = $this->extract_bb_poll_data($body,[ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]);
}
if ($obj) {
$obj['url'] = $mid;
$obj['attributedTo'] = channel_url($channel);
@ -1642,7 +1657,7 @@ class Item extends Controller {
return $ret;
}
function extract_poll_data(&$body,$item) {
function extract_bb_poll_data(&$body,$item) {
$multiple = false;
@ -1653,7 +1668,6 @@ class Item extends Controller {
return false;
}
$obj = [];
$ptr = [];
$matches = null;
@ -1700,4 +1714,42 @@ class Item extends Controller {
}
function extract_poll_data($poll, $item) {
$multiple = intval($poll['multiple_answers']);
$expire_value = intval($poll['expire_value']);
$expire_unit = $poll['expire_unit'];
$question = $poll['question'];
$answers = $poll['answers'];
$obj = [];
$ptr = [];
$obj['type'] = 'Question';
$obj['content'] = bbcode($question);
foreach($answers as $answer) {
if(trim($answer))
$ptr[] = [ 'name' => escape_tags($answer), 'type' => 'Note', 'replies' => [ 'type' => 'Collection', 'totalItems' => 0 ]];
}
if($multiple) {
$obj['anyOf'] = $ptr;
}
else {
$obj['oneOf'] = $ptr;
}
$obj['endTime'] = datetime_convert(date_default_timezone_get(), 'UTC', 'now + ' . $expire_value . ' ' . $expire_unit, ATOM_TIME);
if ($item['item_private']) {
$obj['to'] = Activity::map_acl($item);
}
else {
$obj['to'] = [ ACTIVITY_PUBLIC_INBOX ];
}
return $obj;
}
}

View file

@ -1385,6 +1385,8 @@ function z_status_editor($a, $x, $popup = false) {
'$embedPhotosModalOK' => t('OK'),
'$setloc' => $setloc,
'$voting' => t('Toggle voting'),
'$poll' => t('Toggle poll'),
'$multiple_answers' => ['poll_multiple_answers', t("Allow multiple answers")],
'$feature_voting' => $feature_voting,
'$consensus' => ((array_key_exists('item',$x)) ? $x['item']['item_consensus'] : 0),
'$nocommenttitle' => t('Disable comments'),

View file

@ -1,17 +1,20 @@
/* jot */
.jothidden input[type="text"] {
border: 0px;
margin: 0px;
height: 2.5rem;
width: 100%;
}
.jothidden {
display:none;
}
.jot-poll-option {
position: relative;
}
.poll-option-close {
position: absolute;
right: 0;
top: 0;
padding: 0.25rem 0 0.25rem 0.5rem;
}
#jot-title-wrap,
#jot-pagetitle-wrap,
#jot-category-wrap,
@ -19,7 +22,8 @@
border-bottom: 1px solid rgba(0, 0, 0, .2);
}
#jot-attachment-wrap {
#jot-attachment-wrap,
#jot-poll-wrap {
border-top: 1px solid rgba(0, 0, 0, .2);
}

View file

@ -1629,6 +1629,10 @@ dl.bb-dl > dd > li {
font-size: 100%;
}
.bootstrap-tagsinput input {
height: 2.5rem;
}
/* Abusing theme-green is less work than makeing a new new one */
.theme-green .back-bar .selected-bar {
background-color: #000000;

View file

@ -80,6 +80,9 @@ var activeCommentText = '';
}
});
$('#jot-add-option').on('click', jotAddOption);
$(document).on('click', '.poll-option-close', jotRemoveOption);
function jotSetMime() {
var mtype = $('#id_mimetype').val();
if(mtype == 'text/bbcode')
@ -143,6 +146,7 @@ var activeCommentText = '';
activeCommentID = 0;
},
});
});
function deleteCheckedItems() {
@ -358,6 +362,7 @@ var activeCommentText = '';
function itemCancel() {
$("#jot-title").val('');
$("#profile-jot-text").val('');
$(".jot-poll-option input").val('');
$("#jot-category").tagsinput('removeAll');
postSaveChanges('clean');
@ -366,6 +371,7 @@ var activeCommentText = '';
$(".jothidden").hide();
$("#profile-jot-text").removeClass('jot-expanded');
$("#profile-jot-reset").addClass('d-none');
$("#jot-poll-wrap").addClass('d-none');
$("#jot-preview-content").html('').hide();
editor = false;
{{else}}
@ -561,6 +567,19 @@ var activeCommentText = '';
}
function initPoll() {
$('#jot-poll-wrap').toggleClass('d-none');
}
function jotAddOption() {
var option = '<div class="jot-poll-option form-group"><input class="w-100 border-0" name="poll_answers[]" type="text" value="" placeholder="Option"><div class="poll-option-close"><i class="fa fa-close"></i></div></div>';
$('#jot-poll-options').append(option);
}
function jotRemoveOption(e) {
$(this).closest('.jot-poll-option').remove();
}
</script>
<script>

View file

@ -30,18 +30,18 @@
{{if $webpage}}
<div id="jot-pagetitle-wrap" class="jothidden">
<input name="pagetitle" id="jot-pagetitle" type="text" placeholder="{{$placeholdpagetitle}}" value="{{$pagetitle}}">
<input class="w-100 border-0" name="pagetitle" id="jot-pagetitle" type="text" placeholder="{{$placeholdpagetitle}}" value="{{$pagetitle}}">
{{if $webpage === 8}}
<input type="hidden" id="recip-complete" name="recips" value="{{$recips}}">
{{/if}}
</div>
{{/if}}
<div id="jot-title-wrap" class="jothidden">
<input name="title" id="jot-title" type="text" placeholder="{{$placeholdertitle}}" tabindex="1" value="{{$title}}">
<input class="w-100 border-0" name="title" id="jot-title" type="text" placeholder="{{$placeholdertitle}}" tabindex="1" value="{{$title}}">
</div>
{{if $catsenabled}}
<div id="jot-category-wrap" class="jothidden">
<input name="category" id="jot-category" type="text" placeholder="{{$placeholdercategory}}" value="{{$category}}" data-role="cat-tagsinput">
<input class="w-100 border-0" name="category" id="jot-category" type="text" placeholder="{{$placeholdercategory}}" value="{{$category}}" data-role="cat-tagsinput">
</div>
{{/if}}
{{if $summaryenabled}}
@ -57,6 +57,34 @@
<input class="jot-attachment" name="attachment" id="jot-attachment" type="text" value="{{$attachment}}" readonly="readonly" onclick="this.select();">
</div>
{{/if}}
<div id="jot-poll-wrap" class="p-2 d-none">
<div id="jot-poll-options">
<div class="jot-poll-option form-group">
<input class="w-100 border-0" name="poll_answers[]" type="text" value="" placeholder="Option">
</div>
<div class="jot-poll-option form-group">
<input class="w-100 border-0" name="poll_answers[]" type="text" value="" placeholder="Option">
</div>
</div>
{{include file="field_checkbox.tpl" field=$multiple_answers}}
<div id="jot-poll-tools" class="clearfix">
<div id="poll-tools-left" class="float-left">
<button id="jot-add-option" class="btn btn-outline-secondary btn-sm" type="button" title="" onclick="">
<i class="fa fa-plus"></i> Add option
</button>
</div>
<div id="poll-tools-right" class="float-right">
<div class="input-group">
<input type="text" name="poll_expire_value" class="form-control" value="10" size="3">
<select class="form-control" id="duration-select" name="poll_expire_unit">
<option value="Minutes">min</option>
<option value="Hours">h</option>
<option value="Days" selected="selected">d</option>
</select>
</div>
</div>
</div>
</div>
<div id="profile-jot-submit-wrapper" class="clearfix p-2 jothidden">
<div id="profile-jot-submit-left" class="btn-toolbar float-left">
{{if $bbcode}}
@ -125,6 +153,11 @@
<i id="profile-encrypt" class="fa fa-key jot-icons"></i>
</button>
{{/if}}
<button type="button" id="profile-poll-wrapper" class="btn btn-outline-secondary btn-sm" title="{{$poll}}" onclick="initPoll();">
<i id="profile-poll" class="fa fa-bar-chart jot-icons"></i>
</button>
{{if $feature_nocomment}}
<button id="profile-nocomment-wrapper" class="btn btn-outline-secondary btn-sm" title="{{$nocommenttitle}}" onclick="toggleNoComment();return false;">
<i id="profile-nocomment" class="fa fa-comments jot-icons"></i>
@ -163,6 +196,7 @@
{{if $feature_encrypt}}
<a class="dropdown-item" href="#" onclick="red_encrypt('{{$cipher}}','#profile-jot-text',$('#profile-jot-text').val());return false;"><i class="fa fa-key"></i>&nbsp;{{$encrypt}}</a>
{{/if}}
<a class="dropdown-item" href="#" onclick="initPoll(); return false"><i id="profile-poll" class="fa fa-bar-chart jot-icons"></i>&nbsp;{{$poll}}</a>
{{if $feature_nocomment}}
<a class="dropdown-item" href="#" onclick="toggleNoComment(); return false;"><i id="profile-nocomment-sub" class="fa fa-comments"></i>&nbsp;{{$nocommenttitlesub}}</a>
{{/if}}