├── .editorconfig ├── .gitignore ├── LICENSE.txt ├── README.md ├── assets ├── javascripts │ └── discourse │ │ ├── controllers │ │ └── poll-ui.js.es6 │ │ ├── initializers │ │ └── poll-ui.js.es6 │ │ ├── templates │ │ └── poll-ui.hbs │ │ └── views │ │ └── poll-ui.js.es6 └── stylesheets │ └── poll-ui.scss ├── config ├── locales │ ├── client.de.yml │ ├── client.en.yml │ ├── client.es.yml │ ├── client.fr.yml │ ├── client.zh_CN.yml │ ├── server.de.yml │ ├── server.en.yml │ ├── server.es.yml │ ├── server.fr.yml │ └── server.zh_CN.yml └── settings.yml ├── plugin.rb ├── screenshot-action.gif ├── screenshot-admin-settings.png ├── screenshot-composer-with-answers.png └── screenshot-composer.png /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*.*] 8 | indent_style = space 9 | indent_size = 2 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## THIS PLUGIN IS NOW PART OF CORE AND IS NO LONGER SUPPORTED 2 | 3 | # Poll UI Plugin 4 | This plugin adds support for inserting a poll into the composer window via a UI. 5 | 6 | Composer Window Button 7 | ![](https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/master/screenshot-composer.png) 8 | 9 | Admin Settings 10 | ![](https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/master/screenshot-admin-settings.png) 11 | 12 | In Action 13 | ![](https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/master/screenshot-action.gif) 14 | 15 | Still of the Plugin using the With Answers option 16 | ![](https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/master/screenshot-composer-with-answers.png) 17 | 18 | ## How to Help 19 | 20 | - Create a PR with a new translation! 21 | - Log Issues 22 | - Submit PRs to help resolve issues 23 | 24 | ## Installation 25 | 26 | Follow the directions at [Install a Plugin](https://meta.discourse.org/t/install-a-plugin/19157) using https://github.com/cpradio/discourse-plugin-poll-ui.git as the repository URL. 27 | 28 | ## Authors 29 | 30 | Matthew Wilkin 31 | 32 | ## License 33 | 34 | GNU GPL v2 35 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/controllers/poll-ui.js.es6: -------------------------------------------------------------------------------- 1 | import ModalFunctionality from 'discourse/mixins/modal-functionality'; 2 | 3 | export default Ember.Controller.extend(ModalFunctionality, { 4 | pollName: "", 5 | pollType: "regular", 6 | pollMinValue: 1, 7 | pollMaxValue: 1, 8 | pollStepValue: 1, 9 | pollTypes: [ 10 | { 'title': I18n.t("poll_ui.poll_type.regular"), 'value': "regular" }, 11 | { 'title': I18n.t("poll_ui.poll_type.multiple"), 'value': "multiple" }, 12 | { 'title': I18n.t("poll_ui.poll_type.number"), 'value': "number" } 13 | ], 14 | pollOptions: "", 15 | pollAnswerValue: "", 16 | pollMakePublic: false, 17 | choicesClass: Discourse.SiteSettings.poll_ui_provide_answers ? "has-answers" : "no-answers", 18 | canProvideAnswers: Discourse.SiteSettings.poll_ui_provide_answers, 19 | 20 | isNumberPoll: function() { 21 | return this.get("pollType") === "number"; 22 | }.property("pollType"), 23 | 24 | isMultipleOrNumberPoll: function() { 25 | return this.get("pollType") === "multiple" 26 | || this.get("pollType") === "number"; 27 | }.property("pollType"), 28 | 29 | // Validate the Minimum Value. 30 | minValueValidation: function() { 31 | var mustBeNumeric = new RegExp(/^[\d]+$/), 32 | minValue = this.get('pollMinValue'), 33 | intMinValue = parseInt(this.get('pollMinValue')), 34 | intMaxValue = parseInt(this.get('pollMaxValue')); 35 | if (Ember.isEmpty(minValue) || !parseInt(minValue) || !mustBeNumeric.test(minValue)) { 36 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_min_must_be_numeric") }); 37 | } 38 | 39 | if (intMinValue > intMaxValue) { 40 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_min_must_be_less_than_max") }); 41 | } 42 | 43 | return Discourse.InputValidation.create({ok: true}); 44 | }.property('pollMinValue', 'pollMaxValue'), 45 | 46 | // Validate the Maximum Value. 47 | maxValueValidation: function() { 48 | var mustBeNumeric = new RegExp(/^[\d]+$/), 49 | maxValue = this.get('pollMaxValue'); 50 | if (Ember.isEmpty(maxValue) || !parseInt(maxValue) || !mustBeNumeric.test(maxValue)) { 51 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_max_must_be_numeric") }); 52 | } 53 | 54 | return Discourse.InputValidation.create({ok: true}); 55 | }.property('pollMaxValue'), 56 | 57 | // Validate the Step Value. 58 | stepValueValidation: function() { 59 | var mustBeNumeric = new RegExp(/^[\d]+$/), 60 | stepValue = this.get('pollStepValue'), 61 | intStepValue = parseInt(this.get('pollStepValue')), 62 | intMaxValue = parseInt(this.get('pollMaxValue')); 63 | if (Ember.isEmpty(stepValue) || !parseInt(stepValue) || !mustBeNumeric.test(stepValue)) { 64 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_step_must_be_numeric") }); 65 | } 66 | 67 | if (intStepValue > intMaxValue) { 68 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_step_must_be_less_than_max") }); 69 | } 70 | 71 | return Discourse.InputValidation.create({ok: true}); 72 | }.property('pollStepValue', 'pollMaxValue'), 73 | 74 | // Validate the Options 75 | optionsValidation: function() { 76 | if (this.get("pollType") == "number") 77 | return Discourse.InputValidation.create({ok: true}); 78 | 79 | var options = this.get('pollOptions'), 80 | numOptions = (options.match(/^(.*)$/gm) || []).length, 81 | intMinValue = parseInt(this.get('pollMinValue')), 82 | intMaxValue = parseInt(this.get('pollMaxValue')); 83 | 84 | if (!Ember.isEmpty(this.get("pollOptions")) && numOptions < 2) { 85 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_options_must_have_two_entries") }); 86 | } 87 | 88 | if (numOptions < intMinValue || numOptions < intMaxValue) { 89 | return Discourse.InputValidation.create({ failed: true, reason: I18n.t("poll_ui.poll_options_must_be_greater_than_min_max_values") }); 90 | } 91 | }.property('pollType', 'pollOptions', 'pollMinValue', 'pollMaxValue'), 92 | 93 | submitDisabled: function() { 94 | if (this.get("minValueValidation.failed")) return true; 95 | if (this.get("maxValueValidation.failed")) return true; 96 | if (this.get("stepValueValidation.failed")) return true; 97 | if (this.get("optionsValidation.failed")) return true; 98 | if (this.get("pollType") !== "number" && Ember.isEmpty(this.get("pollOptions"))) return true; 99 | return false; 100 | }.property('pollType', 'pollOptions', 'minValueValidation.failed', 'maxValueValidation.failed', 'stepValueValidation.failed', 'optionsValidation.failed'), 101 | 102 | actions: { 103 | apply: function() { 104 | var name = this.get("pollName"), type = this.get("pollType"), 105 | minValue = this.get("pollMinValue"), maxValue = this.get("pollMaxValue"), 106 | stepValue = this.get("pollStepValue"), options = this.get("pollOptions"), 107 | answerValue = this.get("pollAnswerValue"), makePublic = this.get("pollMakePublic"), 108 | self = this, composerOutput = ""; 109 | 110 | composerOutput += "[poll"; 111 | composerOutput += (name) ? " name='" + name.replace(/\s/g, '_') + "'" : ""; 112 | composerOutput += (type && type != "regular") ? " type=" + type : ""; 113 | composerOutput += (minValue) ? " min=" + minValue : ""; 114 | composerOutput += (maxValue) ? " max=" + maxValue : ""; 115 | composerOutput += (stepValue && type === "number") ? " step=" + stepValue : ""; 116 | composerOutput += (makePublic || makePublic === 'checked') ? " public=true" : ""; 117 | composerOutput += "]"; 118 | composerOutput += (options && type !== "number") ? "\r\n" + options.replace(/^(.*)/gmi, "* $1") + "\r\n" : ""; 119 | composerOutput += "[/poll]"; 120 | 121 | if (!Ember.isEmpty(answerValue)) { 122 | composerOutput += "\r\n
" + I18n.t("poll_ui.poll_answer_summary_title") + "\r\n"; 123 | composerOutput += answerValue + "\r\n
"; 124 | } 125 | 126 | if (self.composerViewOld) 127 | self.composerViewOld.addMarkdown(composerOutput); 128 | else if (self.composerView) { 129 | self.composerView._addText(self.composerView._getSelected(), composerOutput); 130 | } 131 | this.send('closeModal'); 132 | } 133 | }, 134 | 135 | refresh: function() { 136 | }, 137 | 138 | onShow: function() { 139 | this.setProperties({pollName: "", pollType: "regular", pollMinValue: 1, 140 | pollMaxValue: 1, pollStepValue: 1, pollOptions: "", pollAnswerValue: "", pollMakePublic: false }); 141 | }, 142 | 143 | init: function () { 144 | this._super(); 145 | 146 | this.addObserver("pollType", function() { 147 | this.refresh(); 148 | }.bind(this)); 149 | } 150 | }); -------------------------------------------------------------------------------- /assets/javascripts/discourse/initializers/poll-ui.js.es6: -------------------------------------------------------------------------------- 1 | import { withPluginApi } from 'discourse/lib/plugin-api'; 2 | import { onToolbarCreate } from 'discourse/components/d-editor'; 3 | import NewComposer from 'discourse/components/d-editor'; 4 | import showModal from 'discourse/lib/show-modal'; 5 | import ApplicationRoute from 'discourse/routes/application'; 6 | import ComposerView from 'discourse/views/composer'; 7 | 8 | function priorToApi(container) 9 | { 10 | const siteSettings = container.lookup('site-settings:main'); 11 | 12 | if (siteSettings.poll_ui_enabled) { 13 | if (NewComposer !== "undefined") { 14 | NewComposer.reopen({ 15 | actions: { 16 | showPollUI: function() { 17 | showModal('poll-ui').setProperties({composerView: this}); 18 | } 19 | } 20 | }); 21 | 22 | onToolbarCreate(toolbar => { 23 | toolbar.addButton({ 24 | id: "poll_ui_button", 25 | group: "extras", 26 | icon: "bar-chart", 27 | action: 'showPollUI' 28 | }); 29 | }); 30 | } else { 31 | ApplicationRoute.reopen({ 32 | actions: { 33 | showPollUI: function (composerView) { 34 | showModal('poll-ui'); 35 | this.controllerFor('poll-ui').setProperties({composerViewOld: composerView}); 36 | } 37 | } 38 | }); 39 | 40 | ComposerView.reopen({ 41 | initEditor: function () { 42 | // overwrite and wrap. 43 | this._super(); 44 | var view = this; 45 | var button_text = I18n.t("poll_ui.composer_button_text"); 46 | var btn = $(''); 47 | btn.click(function () { 48 | view.get("controller").send("showPollUI", view); 49 | }); 50 | $("#wmd-button-row,.wmd-button-row").append(btn); 51 | } 52 | }); 53 | } 54 | } 55 | } 56 | 57 | function initializePlugin(api) 58 | { 59 | const siteSettings = api.container.lookup('site-settings:main'); 60 | 61 | if (siteSettings.poll_ui_enabled) { 62 | if (NewComposer !== "undefined") { 63 | NewComposer.reopen({ 64 | actions: { 65 | showPollUI: function () { 66 | showModal('poll-ui').setProperties({composerView: this}); 67 | } 68 | } 69 | }); 70 | 71 | api.onToolbarCreate(toolbar => { 72 | toolbar.addButton({ 73 | id: "poll_ui_button", 74 | group: "extras", 75 | icon: "bar-chart", 76 | action: 'showPollUI' 77 | }); 78 | }); 79 | } 80 | } 81 | } 82 | 83 | export default 84 | { 85 | name: 'poll-ui', 86 | initialize(container) 87 | { 88 | withPluginApi('0.1', api => initializePlugin(api), { noApi: () => priorToApi(container) }); 89 | } 90 | }; -------------------------------------------------------------------------------- /assets/javascripts/discourse/templates/poll-ui.hbs: -------------------------------------------------------------------------------- 1 | 75 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/views/poll-ui.js.es6: -------------------------------------------------------------------------------- 1 | import ModalBodyView from 'discourse/views/modal-body'; 2 | 3 | export default ModalBodyView.extend({ 4 | title: function () { 5 | return I18n.t("poll_ui.modal_title"); 6 | }.property() 7 | }); -------------------------------------------------------------------------------- /assets/stylesheets/poll-ui.scss: -------------------------------------------------------------------------------- 1 | .wmd-poll-ui-button:before { 2 | content: "\f080" 3 | } 4 | 5 | .poll-ui-modal { 6 | table { 7 | width: 100%; 8 | 9 | td { 10 | padding: 0 .5em; 11 | } 12 | 13 | td:nth-child(even) { 14 | text-align: right; 15 | } 16 | 17 | td .select2-choice { 18 | text-align: initial; 19 | } 20 | 21 | .numeric-field input { 22 | width: 3em; 23 | } 24 | } 25 | 26 | .tip.good { 27 | display: none; 28 | } 29 | 30 | .content { 31 | max-height: 300px; 32 | min-height: 200px; 33 | overflow-y: auto; 34 | padding: 0 .5em; 35 | clear: both; 36 | 37 | .choices { 38 | .d-editor { 39 | border-width: 0; 40 | 41 | .d-editor-container { 42 | padding: 0; 43 | 44 | .d-editor-button-bar { 45 | display: none; 46 | } 47 | 48 | .d-editor-preview { 49 | display: none; 50 | } 51 | } 52 | } 53 | } 54 | 55 | .no-answers { 56 | textarea { 57 | height: 150px; 58 | } 59 | } 60 | 61 | .answer { 62 | .d-editor-container { 63 | padding: 0 10px 0 10px; 64 | } 65 | 66 | .d-editor-preview { 67 | display: none; 68 | } 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /config/locales/client.de.yml: -------------------------------------------------------------------------------- 1 | de: 2 | js: 3 | composer: 4 | poll_ui_button_title: "Umfrage erstellen" 5 | poll_ui: 6 | composer_button_text: "Umfrage erstellen" 7 | modal_title: "Umfrage erstellen" 8 | poll_name_label: "Name:" 9 | poll_name_placeholder: "Titel der Umfrage" 10 | poll_type_label: "Typ:" 11 | poll_min_multiple_label: "Minimale Anzahl wählbarer Optionen:" 12 | poll_min_numeric_label: "Anfang des Wertebereiches:" 13 | poll_min_placeholder: "1, 2, 3, ..." 14 | poll_min_must_be_numeric: "Dieser Wert muss eine Zahl sein." 15 | poll_min_must_be_less_than_max: "Dieser Wert muss kleiner sein als die Maximale Anzahl." 16 | poll_max_multiple_label: "Maximale Anzahl wählbarer Optionen:" 17 | poll_max_numeric_label: "Ende des Wertebereiches:" 18 | poll_max_placeholder: "1, 2, 3, ..." 19 | poll_max_must_be_numeric: "Dieser Wert muss eine Zahl sein." 20 | poll_step_label: "Schritte zwischen Werten:" 21 | poll_step_placeholder: "1, 2, 3, ..." 22 | poll_step_must_be_numeric: "Dieser Wert muss eine Zahl sein." 23 | poll_step_must_be_less_than_max: "Dieser Wert muss kleiner sein als das Ende des Wertebereiches." 24 | poll_options_label: "Wählbare Optionen: (eine pro Zeile)" 25 | poll_option_delete: "Löschen" 26 | poll_options_must_have_two_entries: "Es muss mindestens 2 wählbare Optionen geben." 27 | poll_options_must_be_greater_than_min_max_values: "Es muss mehr wählbare Optionen geben als bei Minimale/Maximale Anzahl bzw. Anfang/Ende des Wertebereiches definiert wurde." 28 | poll_answer_summary_title: "Antwort anzeigen" 29 | poll_answer_label: "Antwort zur Umfrage: (optional)" 30 | insert_button: "Erstellen" 31 | poll_type: 32 | regular: "Normal" 33 | multiple: "Mehrfach" 34 | number: "Zahlen" 35 | -------------------------------------------------------------------------------- /config/locales/client.en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | js: 3 | composer: 4 | poll_ui_button_title: "Insert Poll" 5 | poll_ui: 6 | composer_button_text: "Insert Poll" 7 | modal_title: "Insert Poll" 8 | poll_name_label: "Name:" 9 | poll_name_placeholder: "Enter Poll Name" 10 | poll_type_label: "Type:" 11 | poll_min_multiple_label: "Minimum Number of Entries:" 12 | poll_min_numeric_label: "Start of Range:" 13 | poll_min_placeholder: "1,2, 3, ..." 14 | poll_min_must_be_numeric: "This value must be a number." 15 | poll_min_must_be_less_than_max: "This value must be less than the Maximum Number/End of Range." 16 | poll_max_multiple_label: "Maximum Number of Entries:" 17 | poll_max_numeric_label: "End of Range:" 18 | poll_max_placeholder: "1, 2, 3, ..." 19 | poll_max_must_be_numeric: "This value must be a number." 20 | poll_step_label: "Steps between Numbers:" 21 | poll_step_placeholder: "1, 2, 3, ..." 22 | poll_step_must_be_numeric: "This value must be a number." 23 | poll_step_must_be_less_than_max: "This value must be less than the Maximum Number/End of Range." 24 | poll_options_label: "Poll Choices: (one option per line)" 25 | poll_option_delete: "Delete" 26 | poll_options_must_have_two_entries: "Choices must have at least 2 options." 27 | poll_options_must_be_greater_than_min_max_values: "Choices must have more options than defined in the Minimum Number/Start of Range and Maximum Number/End of Range fields." 28 | poll_answer_summary_title: "View Answer" 29 | poll_answer_label: "Answer to Poll: (optional)" 30 | poll_make_public_label: "Make Public Poll" 31 | insert_button: "Insert Poll" 32 | poll_type: 33 | regular: "Regular" 34 | multiple: "Multiple" 35 | number: "Number" -------------------------------------------------------------------------------- /config/locales/client.es.yml: -------------------------------------------------------------------------------- 1 | es: 2 | js: 3 | composer: 4 | poll_ui_button_title: "Crear encuesta" 5 | poll_ui: 6 | composer_button_text: "Crear encuesta" 7 | modal_title: "Crear encuesta" 8 | poll_name_label: "Nombre:" 9 | poll_name_placeholder: "Introduce el nombre de la encuesta" 10 | poll_type_label: "Tipo:" 11 | poll_min_multiple_label: "Mínimo de opciones que habrá que votar:" 12 | poll_min_numeric_label: "Primera cifra del rango numérico:" 13 | poll_min_placeholder: "1,2, 3, ..." 14 | poll_min_must_be_numeric: "Este valor debe ser un número." 15 | poll_min_must_be_less_than_max: "Este valor debe ser menor que el Máximo / Última cifra del rango." 16 | poll_max_multiple_label: "Máximo de opciones a votar:" 17 | poll_max_numeric_label: "Última cifra del rango numérico:" 18 | poll_max_placeholder: "1, 2, 3, ..." 19 | poll_max_must_be_numeric: "Este valor debe ser un número." 20 | poll_step_label: "Intervalo entre números:" 21 | poll_step_placeholder: "1, 2, 3, ..." 22 | poll_step_must_be_numeric: "Este valor debe ser un número." 23 | poll_step_must_be_less_than_max: "Este valor debe ser menor que el Máximo / Última cifra del rango.." 24 | poll_options_label: "Opciones de la encuesta: (una opción por línea)" 25 | poll_option_delete: "Eliminar" 26 | poll_options_must_have_two_entries: "Debe haber al menos 2 opciones." 27 | poll_options_must_be_greater_than_min_max_values: "Debe haber más opciones que el Mínimo de opciones a votar / Posiciones entre la Primera y la Última cifras del rango." 28 | poll_answer_summary_title: "Ver respuesta/pista" 29 | poll_answer_label: "Respuesta/pista de la Encuesta: (opcional)" 30 | poll_make_public_label: "Hacer públicos los votantes" 31 | insert_button: "Crear Encuesta" 32 | poll_type: 33 | regular: "Normal" 34 | multiple: "Múltiple" 35 | number: "Numérica" 36 | -------------------------------------------------------------------------------- /config/locales/client.fr.yml: -------------------------------------------------------------------------------- 1 | fr: 2 | js: 3 | composer: 4 | poll_ui_button_title: "Créer un sondage" 5 | poll_ui: 6 | composer_button_text: "Créer le sondage" 7 | modal_title: "Créer un sondage" 8 | poll_name_label: "Nom :" 9 | poll_name_placeholder: "Entrez un nom pour le sondage" 10 | poll_type_label: "Format :" 11 | poll_min_multiple_label: "Réponses minimum :" 12 | poll_min_numeric_label: "Valeur de départ :" 13 | poll_min_placeholder: "1, 2, 3, ..." 14 | poll_min_must_be_numeric: "Cette valeur doit être un chiffre" 15 | poll_min_must_be_less_than_max: "Ce chiffre doit être inférieure à la valeur maximale." 16 | poll_max_multiple_label: "Réponses maximales :" 17 | poll_max_numeric_label: "Valeur finale :" 18 | poll_max_placeholder: "1, 2, 3, ..." 19 | poll_max_must_be_numeric: "Vous devez inscrire un chiffre." 20 | poll_step_label: "Sauts entre les valeurs :" 21 | poll_step_placeholder: "1, 2, 3, ..." 22 | poll_step_must_be_numeric: "Vous devez inscrire un chiffre." 23 | poll_step_must_be_less_than_max: "Ce chiffre doit être inférieure à la valeur maximale" 24 | poll_options_label: "Choix possibles : (un par ligne)" 25 | poll_option_delete: "Supprimer" 26 | poll_options_must_have_two_entries: "Vous devez proposer au moins deux choix" 27 | poll_options_must_be_greater_than_min_max_values: "Vous devez proposer plus de choix que le nombre de réponses minimum et moins que les réponses maximales" 28 | poll_answer_summary_title: "Voir la réponse" 29 | poll_answer_label: "Réponse à la question : (facultatif)" 30 | poll_make_public_label: "Rendre les votes publics" 31 | insert_button: "Poster le sondage" 32 | poll_type: 33 | regular: "Simple" 34 | multiple: "Choix multiples" 35 | number: "Nombres" 36 | -------------------------------------------------------------------------------- /config/locales/client.zh_CN.yml: -------------------------------------------------------------------------------- 1 | zh_CN: 2 | js: 3 | composer: 4 | poll_ui_button_title: "发起投票" 5 | poll_ui: 6 | composer_button_text: "发起投票" 7 | modal_title: "发起投票" 8 | poll_name_label: "投票标题:" 9 | poll_name_placeholder: "输入投票标题" 10 | poll_type_label: "投票类型:" 11 | poll_min_multiple_label: "最少可选项数:" 12 | poll_min_numeric_label: "开头数字:" 13 | poll_min_placeholder: "1,2,3,..." 14 | poll_min_must_be_numeric: "此处必须填写一个数字。" 15 | poll_min_must_be_less_than_max: "必须小于最多可选项项数/最低排名数。" 16 | poll_max_multiple_label: "最多可选项数:" 17 | poll_max_numeric_label: "结尾数字:" 18 | poll_max_placeholder: "1,2,3,..." 19 | poll_max_must_be_numeric: "此处必须填写一个数字。" 20 | poll_step_label: "前后两数差" 21 | poll_step_placeholder: "1,2,3,..." 22 | poll_step_must_be_numeric: "此处必须填写一个数字。" 23 | poll_step_must_be_less_than_max: "必须小于最多可选项项数/最低排名数。" 24 | poll_options_label: "编辑投票选项:(每行一项)" 25 | poll_option_delete: "删除" 26 | poll_options_must_have_two_entries: "Choices must have at least 2 options.必须填写两个以上投票选项。" 27 | poll_options_must_be_greater_than_min_max_values: "Choices 最少选择1项/最高排名,最多不超过所有可选选项数/最低排名。" 28 | poll_answer_summary_title: "显示结果" 29 | poll_answer_label: "投票答案:(可选)" 30 | insert_button: "发起投票" 31 | poll_type: 32 | regular: "单选" 33 | multiple: "多选" 34 | number: "排名" 35 | -------------------------------------------------------------------------------- /config/locales/server.de.yml: -------------------------------------------------------------------------------- 1 | de: 2 | site_settings: 3 | poll_ui_enabled: 'Beim Verfassen den Knopf zum Erstellen von Umfragen anzeigen?' 4 | poll_ui_provide_answers: 'Die Möglichkeit einräumen eine Antwort auf Umfragen zu geben?' 5 | -------------------------------------------------------------------------------- /config/locales/server.en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | site_settings: 3 | poll_ui_enabled: 'Show Insert Poll button on composer window?' 4 | poll_ui_provide_answers: 'Provide the ability to provide an answer?' -------------------------------------------------------------------------------- /config/locales/server.es.yml: -------------------------------------------------------------------------------- 1 | es: 2 | site_settings: 3 | poll_ui_enabled: '¿Mostrar el botón Crear encuesta en el editor de texto?' 4 | poll_ui_provide_answers: '¿Añadir la posibilidad de proporcionar la respuesta o una pista?' 5 | -------------------------------------------------------------------------------- /config/locales/server.fr.yml: -------------------------------------------------------------------------------- 1 | fr: 2 | site_settings: 3 | poll_ui_enabled: 'Activer le plugin Poster un sondage ?' 4 | poll_ui_provide_answers: 'Possibilité de rajouter une réponse au sondage' 5 | -------------------------------------------------------------------------------- /config/locales/server.zh_CN.yml: -------------------------------------------------------------------------------- 1 | zh_CN: 2 | site_settings: 3 | poll_ui_enabled: '是否在文本编辑窗口显示发起投票按钮?' 4 | poll_ui_provide_answers: '是否允许提供一个答案?' 5 | -------------------------------------------------------------------------------- /config/settings.yml: -------------------------------------------------------------------------------- 1 | plugins: 2 | poll_ui_enabled: 3 | default: true 4 | client: true 5 | poll_ui_provide_answers: 6 | default: false 7 | client: true -------------------------------------------------------------------------------- /plugin.rb: -------------------------------------------------------------------------------- 1 | # name: discourse-plugin-poll-ui 2 | # about: Add a button to create a poll 3 | # version: 0.6.1 4 | # authors: Matthew Wilkin 5 | # url: https://github.com/cpradio/discourse-plugin-poll-ui 6 | 7 | enabled_site_setting :poll_ui_enabled 8 | 9 | register_asset "javascripts/discourse/templates/poll-ui.hbs" 10 | 11 | register_asset 'stylesheets/poll-ui.scss' -------------------------------------------------------------------------------- /screenshot-action.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/451bb7a18afce9e0e37cd20a9b065c4d3faa09de/screenshot-action.gif -------------------------------------------------------------------------------- /screenshot-admin-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/451bb7a18afce9e0e37cd20a9b065c4d3faa09de/screenshot-admin-settings.png -------------------------------------------------------------------------------- /screenshot-composer-with-answers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/451bb7a18afce9e0e37cd20a9b065c4d3faa09de/screenshot-composer-with-answers.png -------------------------------------------------------------------------------- /screenshot-composer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpradio/discourse-plugin-poll-ui/451bb7a18afce9e0e37cd20a9b065c4d3faa09de/screenshot-composer.png --------------------------------------------------------------------------------