Skip to content

Commit 44f818e

Browse files
ishanrai05benneyman
authored andcommitted
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 2a91507 commit 44f818e

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

static/js/poll_widget.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ 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+
// We hide the edit pencil button for non-senders
192+
elem.find('.poll-edit-question').hide();
192193
if (widget_data.question !== '') {
193194
// For the non-senders, we hide the question input bar
194195
// when we have a question assigned to the poll
@@ -199,14 +200,78 @@ exports.activate = function (opts) {
199200
elem.find('button.poll-question').attr('disabled', true);
200201
elem.find('input.poll-question').attr('disabled', true);
201202
}
203+
} else {
204+
// Hide the edit pencil icon if the question is still not
205+
// assigned for the senders
206+
if (widget_data.question === '') {
207+
elem.find('.poll-edit-question').hide();
208+
} else {
209+
elem.find('.poll-edit-question').show();
210+
}
202211
}
203212
if (widget_data.question !== '') {
204-
elem.find('button.poll-question').text(i18n.t('Edit question'));
213+
// As soon as a poll-question is assigined
214+
// we change the "Add Question" button to a check button
215+
elem.find('button.poll-question').empty().addClass('fa fa-check poll-question-check');
216+
// The d-none class keeps the cancel editing question button hidden
217+
// as long as "Add Question" button is displayed
218+
elem.find('button.poll-question-remove').removeClass('d-none');
219+
// We hide the whole question bar if question is assigned
220+
elem.find('.poll-question-bar').hide();
205221
elem.find('.poll-comment-bar').show();
206222
} else {
207223
elem.find('.poll-comment-bar').hide();
224+
elem.find('.poll-edit-question').hide();
208225
}
226+
if (is_my_poll) {
227+
// We disable the check button if the input field is empty
228+
// and enable it as soon as something is entered in input field
229+
elem.find('input.poll-question').on('keyup', function () {
230+
if (elem.find('input.poll-question').val().length > 0) {
231+
elem.find('button.poll-question').removeAttr('disabled');
232+
} else {
233+
elem.find('button.poll-question').attr('disabled', true);
209234

235+
}
236+
});
237+
// However doing above leaves the check button disabled
238+
// for the next time when someone is trying to enter a question if
239+
// someone empties the input field and clicks on cancel edit button.
240+
// We fix this by checking if there is text in input field if
241+
// edit question pencil icon is clicked and enable the button if
242+
// there is text in input field.
243+
elem.find('.poll-edit-question').on('click', function () {
244+
if (elem.find('input.poll-question').val().length > 0) {
245+
elem.find('button.poll-question').removeAttr('disabled');
246+
}
247+
});
248+
}
249+
elem.find(".poll-edit-question").on('click', function () {
250+
// As soon as edit question button is clicked
251+
// we hide the Question and the edit question pencil button
252+
// and display the input box for editing the question
253+
elem.find('.poll-question-header').hide();
254+
elem.find('.poll-question-bar').show();
255+
elem.find('.poll-edit-question').hide();
256+
elem.find('input.poll-question').empty().val(widget_data.question).select();
257+
});
258+
259+
elem.find("button.poll-question").on('click', function () {
260+
if (widget_data.question !== '') {
261+
// we display the question and hide the input box for editing
262+
elem.find(".poll-question-bar").hide();
263+
elem.find('.poll-question-header').show();
264+
}
265+
});
266+
267+
elem.find("button.poll-question-remove").on('click', function () {
268+
// On clicking the cross i.e. cancel editing button
269+
// we display the previos question as it is
270+
// and hide the input box and buttons for editing
271+
elem.find('.poll-question-bar').hide();
272+
elem.find('.poll-edit-question').show();
273+
elem.find('.poll-question-header').show();
274+
});
210275
elem.find("button.poll-vote").on('click', function (e) {
211276
e.stopPropagation();
212277
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)