aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Item.php61
-rw-r--r--include/conversation.php4
-rw-r--r--view/css/conversation.css20
-rw-r--r--view/theme/redbasic/css/style.css4
-rwxr-xr-xview/tpl/jot-header.tpl19
-rwxr-xr-xview/tpl/jot.tpl40
6 files changed, 133 insertions, 15 deletions
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 4b866eace..86b5c1c7a 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -271,7 +271,9 @@ 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.
// If using the API from a device (leaf node) you must set origin to 1 (default) or leave unset.
@@ -920,7 +922,21 @@ class Item extends Controller {
$mid = z_root() . '/item/' . $uuid;
}
- $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);
@@ -1397,7 +1413,7 @@ class Item extends Controller {
return $ret;
}
- function extract_poll_data(&$body,$item) {
+ function extract_bb_poll_data(&$body,$item) {
$multiple = false;
@@ -1457,5 +1473,44 @@ 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;
+
+ }
+
+
}
diff --git a/include/conversation.php b/include/conversation.php
index 0098a694d..ba0f61196 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -1293,7 +1293,7 @@ function hz_status_editor($a, $x, $popup = false) {
$feature_voting = feature_enabled($x['profile_uid'], 'consensus_tools');
if(x($x, 'hide_voting'))
$feature_voting = false;
-
+
$feature_nocomment = feature_enabled($x['profile_uid'], 'disable_comments');
if(x($x, 'disable_comments'))
$feature_nocomment = false;
@@ -1441,6 +1441,8 @@ function hz_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'),
diff --git a/view/css/conversation.css b/view/css/conversation.css
index f7804f5dd..287d662ae 100644
--- a/view/css/conversation.css
+++ b/view/css/conversation.css
@@ -1,15 +1,18 @@
/* jot */
+.jothidden {
+ display:none;
+}
-.jothidden input[type="text"] {
- border: 0px;
- margin: 0px;
- height: 2.5rem;
- width: 100%;
+.jot-poll-option {
+ position: relative;
}
-.jothidden {
- display:none;
+.poll-option-close {
+ position: absolute;
+ right: 0;
+ top: 0;
+ padding: 0.25rem 0 0.25rem 0.5rem;
}
#jot-title-wrap,
@@ -18,7 +21,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);
}
diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css
index 3bee84378..1ababecfc 100644
--- a/view/theme/redbasic/css/style.css
+++ b/view/theme/redbasic/css/style.css
@@ -1605,6 +1605,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;
diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl
index 7b1f4ee05..d519fd666 100755
--- a/view/tpl/jot-header.tpl
+++ b/view/tpl/jot-header.tpl
@@ -58,6 +58,9 @@ var activeCommentText = '';
$('#id_mimetype').on('load', jotSetMime);
$('#id_mimetype').on('change', jotSetMime);
+ $('#jot-add-option').on('click', jotAddOption);
+ $(document).on('click', '.poll-option-close', jotRemoveOption);
+
function jotSetMime() {
var mtype = $('#id_mimetype').val();
if(mtype == 'text/bbcode')
@@ -122,6 +125,7 @@ var activeCommentText = '';
activeCommentID = 0;
},
});
+
});
function deleteCheckedItems() {
@@ -309,6 +313,7 @@ var activeCommentText = '';
function itemCancel() {
$("#jot-title").val('');
$("#profile-jot-text").val('');
+ $(".jot-poll-option input").val('');
$("#jot-category").tagsinput('removeAll');
postSaveChanges('clean');
@@ -317,6 +322,7 @@ var activeCommentText = '';
$(".jothidden").hide();
$("#profile-jot-text").removeClass('jot-expanded');
$("#profile-jot-tools").addClass('d-none');
+ $("#jot-poll-wrap").addClass('d-none');
$("#jot-preview-content").html('').hide();
editor = false;
{{else}}
@@ -512,6 +518,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>
diff --git a/view/tpl/jot.tpl b/view/tpl/jot.tpl
index b4616db6d..9f2860b2f 100755
--- a/view/tpl/jot.tpl
+++ b/view/tpl/jot.tpl
@@ -30,15 +30,15 @@
{{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}}">
</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}}
<div id="jot-text-wrap">
@@ -59,6 +59,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}}
@@ -132,6 +160,11 @@
<i id="profile-voting" class="fa fa-square-o 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>
@@ -176,6 +209,7 @@
{{if $feature_voting}}
<a class="dropdown-item" href="#" onclick="toggleVoting(); return false;"><i id="profile-voting-sub" class="fa fa-square-o"></i>&nbsp;{{$voting}}</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}}