2 * simple form output jquery binding
3 * enables dynamic form output to a given target
8 "mwe-select_file" : "Select file",
9 "mwe-more_licence_options" : "For more licence options, view the <a href=\"$1\">normal upload page<\/a>",
10 "mwe-select_ownwork" : "I am uploading entirely my own work, and licencing it under:",
11 "mwe-licence_cc-by-sa" : "Creative Commons Share Alike (3.0)",
12 "mwe-upload" : "Upload file",
13 "mwe-destfilename" : "Destination filename:",
14 "mwe-summary" : "Summary",
15 "mwe-error_not_loggedin" : "You do not appear to be logged in or do not have upload privileges.",
16 "mwe-watch-this-file" : "Watch this file",
17 "mwe-ignore-any-warnings" : "Ignore any warnings"
20 var default_form_options = {
22 'licence_options':['cc-by-sa'],
28 $.fn.simpleUploadForm = function( opt , callback ) {
31 for ( var i in default_form_options ) {
33 opt[i] = default_form_options[i];
36 // first do a reality check on the options:
37 if ( !opt.api_target ) {
38 $( this.selector ).html( 'Error: Missing api target' );
42 // @@todo this is just a proof of concept
43 // much todo to improved this web form
44 get_mw_token( 'File:MyRandomFileTokenCheck', opt.api_target, function( eToken ) {
45 if ( !eToken || eToken == '+\\' ) {
46 $( this.selector ).html( gM( 'mwe-error_not_loggedin' ) );
50 // build an upload form:
52 '<form id="suf-upload" enctype="multipart/form-data" action="' + opt.api_target + '" method="post">' +
54 '<input type="hidden" name="action" value="upload">' +
55 '<input type="hidden" name="format" value="jsonfm">' +
56 '<input type="hidden" name="token" value="' + eToken + '">' +
59 '<label for="wpUploadFile">' + gM( 'mwe-select_file' ) + '</label><br>' +
60 '<input id="wpUploadFile" type="file" style="display: inline;" name="wpUploadFile" size="15"/><br>' +
62 '<label for="wpDestFile">' + gM( 'mwe-destfilename' ) + '</label><br>' +
63 '<input id="wpDestFile" type="text" id="wpDestFile" name="wpDestFile" size="30" /><br>' +
65 '<label for="wpUploadDescription">' + gM( 'mwe-summary' ) + ':</label><br>' +
66 '<textarea id="wpUploadDescription" cols="30" rows="3" name="wpUploadDescription" tabindex="3"/><br>' +
68 '<input type="checkbox" value="true" id="wpWatchthis" name="watch" tabindex="7"/>' +
69 '<label for="wpWatchthis">' + gM( 'mwe-watch-this-file' ) + '</label>' +
71 '<input type="checkbox" value="true" id="wpIgnoreWarning" name="ignorewarnings" tabindex="8"/>' +
72 '<label for="wpIgnoreWarning">' + gM( 'mwe-ignore-any-warnings' ) + '</label></br>' +
74 '<div id="wpDestFile-warning"></div>' +
75 '<div style="clear:both;"></div>' + '<p>' +
77 gM( 'mwe-select_ownwork' ) + '<br>' +
78 '<input type="checkbox" id="wpLicence" name="wpLicence" value="cc-by-sa">' + gM( 'mwe-licence_cc-by-sa' ) + '</p>' +
80 '<input type="submit" accesskey="s" value="' + gM( 'mwe-upload' ) + '" name="wpUploadBtn" id="wpUploadBtn" tabindex="9"/>' +
81 // close the form and div
85 // set the target with the form output:
86 $( _this.selector ).html( o );
87 // by default dissable:
88 $j( '#wpUploadBtn' ).attr( 'disabled', 'disabled' );
90 // set up basic licence binding:
91 $j( '#wpLicence' ).click( function() {
92 if ( $j( this ).is( ':checked' ) ) {
93 $j( '#wpUploadBtn' ).removeAttr( 'disabled' );
95 $j( '#wpUploadBtn' ).attr( 'disabled', 'disabled' );
98 // do destination fill:
99 // @@should integrate with doDestinationFill on upload page
100 $j( "#wpUploadFile" ).change( function() {
101 var path = $j( this ).val();
102 // Find trailing part
103 var slash = path.lastIndexOf( '/' );
104 var backslash = path.lastIndexOf( '\\' );
106 if ( slash == -1 && backslash == -1 ) {
108 } else if ( slash > backslash ) {
109 fname = path.substring( slash + 1, 10000 );
111 fname = path.substring( backslash + 1, 10000 );
113 fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1, 10000 ) ).replace( / /g, '_' );
115 $j( "#wpDestFile" ).val( fname );
116 // do destination check
117 $j( "#wpDestFile" ).doDestCheck( {
118 'warn_target':'#wpDestFile-warning'
123 // do destination check:
124 $j( "#wpDestFile" ).change( function() {
125 $j( "#wpDestFile" ).doDestCheck( {
126 'warn_target':'#wpDestFile-warning'
130 if ( typeof opt.ondone_cb == 'undefined' )
131 opt.ondone_cb = false;
133 // set up the binding per the config
134 if ( opt.enable_fogg ) {
135 $j( "#wpUploadFile" ).firefogg( {
136 // an api url (we won't submit directly to action of the form)
137 'api_url' : opt.api_target,
138 'form_rewrite': true,
139 'target_edit_from' : '#suf-upload',
140 'new_source_cb' : function( orgFilename, oggName ) {
141 $j( "#wpDestFile" ).val( oggName ).doDestCheck( {
142 warn_target: "#wpDestFile-warning"
145 'done_upload_cb' : opt.ondone_cb