2 * simple form output jquery binding
3 * enables dynamic form output to a given target
8 "select_file" : "Select file",
9 "more_licence_options" : "For more licence options, view the <a href=\"$1\">normal upload page<\/a>",
10 "select_ownwork" : "I am uploading entirely my own work, and licencing it under : ",
11 "licence_cc-by-sa" : "Creative Commons Share Alike (3.0)",
12 "upload" : "Upload file",
13 "destfilename" : "Destination filename : ",
14 "summary" : "Summary",
15 "error_not_loggedin" : "You do not appear to be logged in or do not have upload privlages."
18 var default_form_options
= {
20 'licence_options':['cc-by-sa'],
26 $.fn
.simpleUploadForm = function( opt
, callback
){
29 for(var i
in default_form_options
){
31 opt
[i
] = default_form_options
[i
];
34 //first do a reality check on the options:
35 if( !opt
.api_target
){
36 $(this.selector
).html('Error: Missing api target');
40 //@@todo this is just a proof of concept
41 //much todo to improved this web form
42 get_mw_token('File:MyRandomFileTokenCheck', opt
.api_target
, function(eToken
){
43 if( !eToken
|| eToken
== '+\\' ){
44 $(this.selector
).html( gM('error_not_loggedin') );
48 //build an upload form:
50 '<form id="suf-upload" enctype="multipart/form-data" action="' + opt
.api_target
+ '" method="post">' +
52 '<input type="hidden" name="action" value="upload">'+
53 '<input type="hidden" name="format" value="jsonfm">'+
54 '<input type="hidden" name="token" value="'+ eToken
+'">' +
57 '<label for="wpUploadFile">' + gM('select_file') + '</label><br>'+
58 '<input type="file" style="display: inline;" name="wpUploadFile" size="15"/><br>' +
60 '<label for="wpDestFile">' +gM('destfilename') + '</label><br>'+
61 '<input type="text" name="wpDestFile" size="30" /><br>'+
63 '<label for="wpUploadDescription">' + gM('summary') + ':</label><br>' +
64 '<textarea cols="30" rows="3" name="wpUploadDescription" tabindex="3"/><br>'+
66 '<div id="wpDestFile-warning"></div>' +
68 gM('select_ownwork') + '<br>' +
69 '<input type="checkbox" id="wpLicence" name="wpLicence" value="cc-by-sa">' + gM('licence_cc-by-sa') + '<br>' +
71 '<input type="submit" accesskey="s" value="' + gM('upload') + '" name="wpUploadBtn" id="wpUploadBtn" tabindex="9"/>' +
72 //close the form and div
75 //set the target with the form output:
76 $( _this
.selector
).html( o
);
77 //by default dissable:
78 $j('#wpUploadBtn').attr('disabled', 'disabled');
80 //set up basic licence binding:
81 $j('#wpLicence').click(function(){
82 if( $j(this).is(':checked') ){
83 $j('#wpUploadBtn').removeAttr('disabled');
85 $j('#wpUploadBtn').attr('disabled', 'disabled');
89 if(typeof opt
.ondone_cb
== 'undefined')
90 opt
.ondone_cb
= false;
92 //set up the binding per the config
93 if( opt
.enable_fogg
){
94 $j("#suf-upload [name='wpUploadFile']").firefogg({
95 //an api url (we won't submit directly to action of the form)
96 'api_url' : opt
.api_target
,
98 'target_edit_from' : '#suf-upload',
99 'new_source_cb' : function( orgFilename
, oggName
){
100 $j("#suf-upload [name='wpDestFile']").val( oggName
).doDestCheck({
101 warn_target
: "#wpDestFile-warning"
104 'done_upload_cb' : opt
.ondone_cb