Skip to content

Commit 8e0db9b

Browse files
committed
poll-widget: Change "Edit question" UI to edit-pencil button.
This changes the "Edit question" UI to be just an edit-pencil button rather than a large "Edit question" button for a poll. Fixes part of zulip#11010.
1 parent 0ce7e61 commit 8e0db9b

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

static/js/poll_widget.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ exports.activate = function (opts) {
186186
var widget_data = poll_data.get_widget_data();
187187
var html = templates.render('poll-widget-results', widget_data);
188188
elem.find('ul.poll-widget').html(html);
189-
190189
elem.find('.poll-question-header').text(widget_data.question);
191190
if (!is_my_poll) {
191+
elem.find('.poll-edit-question').hide();
192192
if (widget_data.question !== '') {
193193
// For the non-senders, we hide the question input bar
194194
// when we have a question assigned to the poll
@@ -199,14 +199,56 @@ exports.activate = function (opts) {
199199
elem.find('button.poll-question').attr('disabled', true);
200200
elem.find('input.poll-question').attr('disabled', true);
201201
}
202+
} else {
203+
if (widget_data.question === '') {
204+
elem.find('.poll-edit-question').hide();
205+
} else {
206+
elem.find('.poll-edit-question').show();
207+
}
202208
}
203209
if (widget_data.question !== '') {
204-
elem.find('button.poll-question').text(i18n.t('Edit question'));
210+
elem.find('button.poll-question').empty().addClass('fa fa-check poll-question-check');
211+
elem.find('button.poll-question-remove').removeClass('d-none');
212+
elem.find('.poll-question-bar').hide();
205213
elem.find('.poll-comment-bar').show();
206214
} else {
207215
elem.find('.poll-comment-bar').hide();
216+
elem.find('.poll-edit-question').hide();
208217
}
218+
if (is_my_poll) {
219+
elem.find('input.poll-question').on('keyup', function () {
220+
if (elem.find('input.poll-question').val().length > 0) {
221+
elem.find('button.poll-question').removeAttr('disabled');
222+
} else {
223+
elem.find('button.poll-question').attr('disabled', true);
209224

225+
}
226+
});
227+
elem.find('.poll-edit-question').on('click', function () {
228+
if (elem.find('input.poll-question').val().length > 0) {
229+
elem.find('button.poll-question').removeAttr('disabled');
230+
}
231+
});
232+
}
233+
elem.find(".poll-edit-question").on('click', function () {
234+
elem.find('.poll-question-header').hide();
235+
elem.find('.poll-question-bar').show();
236+
elem.find('.poll-edit-question').hide();
237+
elem.find('input.poll-question').empty().val(widget_data.question).select();
238+
});
239+
240+
elem.find("button.poll-question").on('click', function () {
241+
if (widget_data.question !== '') {
242+
elem.find(".poll-question-bar").hide();
243+
elem.find('.poll-question-header').show();
244+
}
245+
});
246+
247+
elem.find("button.poll-question-remove").on('click', function () {
248+
elem.find('.poll-question-bar').hide();
249+
elem.find('.poll-edit-question').show();
250+
elem.find('.poll-question-header').show();
251+
});
210252
elem.find("button.poll-vote").on('click', function (e) {
211253
e.stopPropagation();
212254
var key = $(e.target).attr('data-key');

static/styles/widgets.scss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,35 @@ button.poll-question:hover {
105105
color: hsl(1, 45%, 50%);
106106
font-size: 12px;
107107
}
108+
109+
.d-none {
110+
display: none;
111+
}
112+
113+
.poll-question-check,
114+
.poll-question-remove {
115+
width: 28px !important;
116+
height: 28px;
117+
border-radius: 3px;
118+
border: 1px solid hsl(0, 0%, 80%);
119+
background-color: hsl(0, 0%, 100%);
120+
}
121+
122+
.poll-question-check:hover,
123+
.poll-question-remove:hover {
124+
border-color: hsl(0, 0%, 60%);
125+
}
126+
127+
.poll-edit-question {
128+
opacity: 0.4;
129+
display: inline-block;
130+
margin-left: 5px;
131+
}
132+
133+
.poll-edit-question:hover {
134+
opacity: 1.0;
135+
}
136+
137+
.poll-question-header {
138+
display: inline-block;
139+
}

static/templates/widgets/poll-widget.handlebars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<div class="poll-widget">
2-
<h4 class="poll-question-header"></h4>
2+
<h4 class="poll-question-header"></h4><i class="fa fa-pencil poll-edit-question"></i>
33
<ul class="poll-widget">
44
</ul>
55
<div class="poll-question-bar">
66
<input type="text" class="poll-question" placeholder="{{t 'Question'}}" />
77
<button class="poll-question">{{t "Add question" }}</button>
8+
<button class="poll-question-remove d-none"><i class="fa fa-remove"></i></button>
89
</div>
910
<div class="poll-comment-bar">
1011
<input type="text" class="poll-comment" placeholder="{{t 'New choice'}}" />

0 commit comments

Comments
 (0)