mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 01:35:12 +00:00
implement poll UI in jot
This commit is contained in:
parent
56d97a876d
commit
72bdd7963f
6 changed files with 131 additions and 16 deletions
|
@ -384,6 +384,7 @@ class Item extends Controller {
|
||||||
$consensus = intval($_REQUEST['consensus']);
|
$consensus = intval($_REQUEST['consensus']);
|
||||||
$nocomment = intval($_REQUEST['nocomment']);
|
$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,
|
// 'origin' (if non-zero) indicates that this network is where the message originated,
|
||||||
// for the purpose of relaying comments to other conversation members.
|
// 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) {
|
if ($obj) {
|
||||||
$obj['url'] = $mid;
|
$obj['url'] = $mid;
|
||||||
$obj['attributedTo'] = channel_url($channel);
|
$obj['attributedTo'] = channel_url($channel);
|
||||||
|
@ -1642,7 +1657,7 @@ class Item extends Controller {
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract_poll_data(&$body,$item) {
|
function extract_bb_poll_data(&$body,$item) {
|
||||||
|
|
||||||
$multiple = false;
|
$multiple = false;
|
||||||
|
|
||||||
|
@ -1653,7 +1668,6 @@ class Item extends Controller {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$obj = [];
|
$obj = [];
|
||||||
$ptr = [];
|
$ptr = [];
|
||||||
$matches = null;
|
$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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1385,6 +1385,8 @@ function z_status_editor($a, $x, $popup = false) {
|
||||||
'$embedPhotosModalOK' => t('OK'),
|
'$embedPhotosModalOK' => t('OK'),
|
||||||
'$setloc' => $setloc,
|
'$setloc' => $setloc,
|
||||||
'$voting' => t('Toggle voting'),
|
'$voting' => t('Toggle voting'),
|
||||||
|
'$poll' => t('Toggle poll'),
|
||||||
|
'$multiple_answers' => ['poll_multiple_answers', t("Allow multiple answers")],
|
||||||
'$feature_voting' => $feature_voting,
|
'$feature_voting' => $feature_voting,
|
||||||
'$consensus' => ((array_key_exists('item',$x)) ? $x['item']['item_consensus'] : 0),
|
'$consensus' => ((array_key_exists('item',$x)) ? $x['item']['item_consensus'] : 0),
|
||||||
'$nocommenttitle' => t('Disable comments'),
|
'$nocommenttitle' => t('Disable comments'),
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
|
|
||||||
/* jot */
|
/* jot */
|
||||||
|
|
||||||
.jothidden input[type="text"] {
|
|
||||||
border: 0px;
|
|
||||||
margin: 0px;
|
|
||||||
height: 2.5rem;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jothidden {
|
.jothidden {
|
||||||
display:none;
|
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-title-wrap,
|
||||||
#jot-pagetitle-wrap,
|
#jot-pagetitle-wrap,
|
||||||
#jot-category-wrap,
|
#jot-category-wrap,
|
||||||
|
@ -19,7 +22,8 @@
|
||||||
border-bottom: 1px solid rgba(0, 0, 0, .2);
|
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);
|
border-top: 1px solid rgba(0, 0, 0, .2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1629,6 +1629,10 @@ dl.bb-dl > dd > li {
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bootstrap-tagsinput input {
|
||||||
|
height: 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
/* Abusing theme-green is less work than makeing a new new one */
|
/* Abusing theme-green is less work than makeing a new new one */
|
||||||
.theme-green .back-bar .selected-bar {
|
.theme-green .back-bar .selected-bar {
|
||||||
background-color: #000000;
|
background-color: #000000;
|
||||||
|
|
|
@ -80,6 +80,9 @@ var activeCommentText = '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#jot-add-option').on('click', jotAddOption);
|
||||||
|
$(document).on('click', '.poll-option-close', jotRemoveOption);
|
||||||
|
|
||||||
function jotSetMime() {
|
function jotSetMime() {
|
||||||
var mtype = $('#id_mimetype').val();
|
var mtype = $('#id_mimetype').val();
|
||||||
if(mtype == 'text/bbcode')
|
if(mtype == 'text/bbcode')
|
||||||
|
@ -143,6 +146,7 @@ var activeCommentText = '';
|
||||||
activeCommentID = 0;
|
activeCommentID = 0;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function deleteCheckedItems() {
|
function deleteCheckedItems() {
|
||||||
|
@ -358,6 +362,7 @@ var activeCommentText = '';
|
||||||
function itemCancel() {
|
function itemCancel() {
|
||||||
$("#jot-title").val('');
|
$("#jot-title").val('');
|
||||||
$("#profile-jot-text").val('');
|
$("#profile-jot-text").val('');
|
||||||
|
$(".jot-poll-option input").val('');
|
||||||
$("#jot-category").tagsinput('removeAll');
|
$("#jot-category").tagsinput('removeAll');
|
||||||
|
|
||||||
postSaveChanges('clean');
|
postSaveChanges('clean');
|
||||||
|
@ -366,6 +371,7 @@ var activeCommentText = '';
|
||||||
$(".jothidden").hide();
|
$(".jothidden").hide();
|
||||||
$("#profile-jot-text").removeClass('jot-expanded');
|
$("#profile-jot-text").removeClass('jot-expanded');
|
||||||
$("#profile-jot-reset").addClass('d-none');
|
$("#profile-jot-reset").addClass('d-none');
|
||||||
|
$("#jot-poll-wrap").addClass('d-none');
|
||||||
$("#jot-preview-content").html('').hide();
|
$("#jot-preview-content").html('').hide();
|
||||||
editor = false;
|
editor = false;
|
||||||
{{else}}
|
{{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>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -30,18 +30,18 @@
|
||||||
|
|
||||||
{{if $webpage}}
|
{{if $webpage}}
|
||||||
<div id="jot-pagetitle-wrap" class="jothidden">
|
<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}}
|
{{if $webpage === 8}}
|
||||||
<input type="hidden" id="recip-complete" name="recips" value="{{$recips}}">
|
<input type="hidden" id="recip-complete" name="recips" value="{{$recips}}">
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div id="jot-title-wrap" class="jothidden">
|
<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>
|
</div>
|
||||||
{{if $catsenabled}}
|
{{if $catsenabled}}
|
||||||
<div id="jot-category-wrap" class="jothidden">
|
<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>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{if $summaryenabled}}
|
{{if $summaryenabled}}
|
||||||
|
@ -57,6 +57,34 @@
|
||||||
<input class="jot-attachment" name="attachment" id="jot-attachment" type="text" value="{{$attachment}}" readonly="readonly" onclick="this.select();">
|
<input class="jot-attachment" name="attachment" id="jot-attachment" type="text" value="{{$attachment}}" readonly="readonly" onclick="this.select();">
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/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-wrapper" class="clearfix p-2 jothidden">
|
||||||
<div id="profile-jot-submit-left" class="btn-toolbar float-left">
|
<div id="profile-jot-submit-left" class="btn-toolbar float-left">
|
||||||
{{if $bbcode}}
|
{{if $bbcode}}
|
||||||
|
@ -125,6 +153,11 @@
|
||||||
<i id="profile-encrypt" class="fa fa-key jot-icons"></i>
|
<i id="profile-encrypt" class="fa fa-key jot-icons"></i>
|
||||||
</button>
|
</button>
|
||||||
{{/if}}
|
{{/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}}
|
{{if $feature_nocomment}}
|
||||||
<button id="profile-nocomment-wrapper" class="btn btn-outline-secondary btn-sm" title="{{$nocommenttitle}}" onclick="toggleNoComment();return false;">
|
<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>
|
<i id="profile-nocomment" class="fa fa-comments jot-icons"></i>
|
||||||
|
@ -163,6 +196,7 @@
|
||||||
{{if $feature_encrypt}}
|
{{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> {{$encrypt}}</a>
|
<a class="dropdown-item" href="#" onclick="red_encrypt('{{$cipher}}','#profile-jot-text',$('#profile-jot-text').val());return false;"><i class="fa fa-key"></i> {{$encrypt}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
<a class="dropdown-item" href="#" onclick="initPoll(); return false"><i id="profile-poll" class="fa fa-bar-chart jot-icons"></i> {{$poll}}</a>
|
||||||
{{if $feature_nocomment}}
|
{{if $feature_nocomment}}
|
||||||
<a class="dropdown-item" href="#" onclick="toggleNoComment(); return false;"><i id="profile-nocomment-sub" class="fa fa-comments"></i> {{$nocommenttitlesub}}</a>
|
<a class="dropdown-item" href="#" onclick="toggleNoComment(); return false;"><i id="profile-nocomment-sub" class="fa fa-comments"></i> {{$nocommenttitlesub}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
Loading…
Reference in a new issue