1 ( function( mw
, $, undefined ) {
4 * Thingy for collecting user feedback on a wiki page
5 * @param {mw.Api} api properly configured to talk to this wiki
6 * @param {mw.Title} the title of the page where you collect feedback
7 * @param {id} a string identifying this feedback form to separate it from others on the same page
9 mw
.Feedback = function( api
, feedbackTitle
) {
12 this.feedbackTitle
= feedbackTitle
;
16 mw
.Feedback
.prototype = {
20 // Set up buttons for dialog box. We have to do it the hard way since the json keys are localized
22 _this
.buttons
[ mw
.msg( 'mwe-upwiz-feedback-cancel' ) ] = function() { _this
.cancel(); };
23 _this
.buttons
[ mw
.msg( 'mwe-upwiz-feedback-submit' ) ] = function() { _this
.submit(); };
25 var $feedbackPageLink
= $j( '<a></a>' ).attr( { 'href': _this
.feedbackTitle
.getUrl(), 'target': '_blank' } );
27 $( '<div style="position:relative;"></div>' ).append(
28 $( '<div class="mwe-upwiz-feedback-mode mwe-upwiz-feedback-form"></div>' ).append(
29 $( '<div style="margin-top:0.4em;"></div>' ).append(
30 $( '<small></small>' ).msg( 'mwe-upwiz-feedback-note',
31 _this
.feedbackTitle
.getNameText(),
34 $( '<div style="margin-top:1em;"></div>' ).append(
35 mw
.msg( 'mwe-upwiz-feedback-subject' ),
37 $( '<input type="text" class="mwe-upwiz-feedback-subject" name="subject" maxlength="60" style="width:99%;"/>' )
39 $( '<div style="margin-top:0.4em;"></div>' ).append(
40 mw
.msg( 'mwe-upwiz-feedback-message' ),
42 $( '<textarea name="message" class="mwe-upwiz-feedback-message" style="width:99%;" rows="5" cols="60"></textarea>' )
45 $( '<div class="mwe-upwiz-feedback-mode mwe-upwiz-feedback-submitting" style="text-align:center;margin:3em 0;"></div>' ).append(
46 mw
.msg( 'mwe-upwiz-feedback-adding' ),
48 $( '<img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" />' )
50 $( '<div class="mwe-upwiz-feedback-mode mwe-upwiz-feedback-error" style="position:relative;"></div>' ).append(
51 $( '<div class="mwe-upwiz-feedback-error-msg style="color:#990000;margin-top:0.4em;"></div>' )
57 title
: mw
.msg( 'mwe-upwiz-feedback-title' ),
59 buttons
: _this
.buttons
62 this.subjectInput
= this.$dialog
.find( 'input.mwe-upwiz-feedback-subject' ).get(0);
63 this.messageInput
= this.$dialog
.find( 'textarea.mwe-upwiz-feedback-message' ).get(0);
67 display: function( s
) {
68 this.$dialog
.dialog( { buttons
:{} } ); // hide the buttons
69 this.$dialog
.find( '.mwe-upwiz-feedback-mode' ).hide(); // hide everything
70 this.$dialog
.find( '.mwe-upwiz-feedback-' + s
).show(); // show the desired div
73 displaySubmitting: function() {
74 this.display( 'submitting' );
77 displayForm: function( contents
) {
78 this.subjectInput
.value
= (contents
&& contents
.subject
) ? contents
.subject
: '';
79 this.messageInput
.value
= (contents
&& contents
.message
) ? contents
.message
: '';
81 this.display( 'form' );
82 this.$dialog
.dialog( { buttons
: this.buttons
} ); // put the buttons back
85 displayError: function( message
) {
86 this.display( 'error' );
87 this.$dialog
.find( '.mwe-upwiz-feedback-error-msg' ).msg( message
);
91 this.$dialog
.dialog( 'close' );
97 // get the values to submit
98 var subject
= this.subjectInput
.value
;
100 var message
= "<small>User agent: " + navigator
.userAgent
+ "</small>\n\n"
101 + this.messageInput
.value
;
102 if ( message
.indexOf( '~~~' ) == -1 ) {
106 this.displaySubmitting();
108 var ok = function( result
) {
109 if ( result
.edit
!== undefined ) {
110 if ( result
.edit
.result
=== 'Success' ) {
111 _this
.$dialog
.dialog( 'close' ); // edit complete, close dialog box
113 _this
.displayError( 'mwe-upwiz-feedback-error1' ); // unknown API result
116 displayError( 'mwe-upwiz-feedback-error2' ); // edit failed
120 var err = function( code
, info
) {
121 displayError( 'mwe-upwiz-feedback-error3' ); // ajax request failed
124 this.api
.newSection( this.feedbackTitle
, subject
, message
, ok
, err
);
126 }, // close submit button function
129 launch: function( contents
) {
130 this.displayForm( contents
);
131 this.$dialog
.dialog( 'open' );
132 this.subjectInput
.focus();
138 } )( window
.mediaWiki
, jQuery
);