@@ -186,9 +186,10 @@ exports.activate = function (opts) {
186
186
var widget_data = poll_data . get_widget_data ( ) ;
187
187
var html = templates . render ( 'poll-widget-results' , widget_data ) ;
188
188
elem . find ( 'ul.poll-widget' ) . html ( html ) ;
189
-
190
189
elem . find ( '.poll-question-header' ) . text ( widget_data . question ) ;
191
190
if ( ! is_my_poll ) {
191
+ // We hide the edit pencil button for non-senders
192
+ elem . find ( '.poll-edit-question' ) . hide ( ) ;
192
193
if ( widget_data . question !== '' ) {
193
194
// For the non-senders, we hide the question input bar
194
195
// when we have a question assigned to the poll
@@ -199,14 +200,78 @@ exports.activate = function (opts) {
199
200
elem . find ( 'button.poll-question' ) . attr ( 'disabled' , true ) ;
200
201
elem . find ( 'input.poll-question' ) . attr ( 'disabled' , true ) ;
201
202
}
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
+ }
202
211
}
203
212
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 ( ) ;
205
221
elem . find ( '.poll-comment-bar' ) . show ( ) ;
206
222
} else {
207
223
elem . find ( '.poll-comment-bar' ) . hide ( ) ;
224
+ elem . find ( '.poll-edit-question' ) . hide ( ) ;
208
225
}
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 ) ;
209
234
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
+ } ) ;
210
275
elem . find ( "button.poll-vote" ) . on ( 'click' , function ( e ) {
211
276
e . stopPropagation ( ) ;
212
277
var key = $ ( e . target ) . attr ( 'data-key' ) ;
0 commit comments