r100124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100123‎ | r100124 | r100125 >
Date:17:24, 18 October 2011
Author:khorn
Status:ok
Tags:fundraising 
Comment:
Merging the fundraising branch of DonationInterface back into trunk.
Adding all the directories which are completely new to the trunk version.
As this is a mid-merge commit, the extension will be broken until the merge is completed.
Modified paths:
  • /trunk/extensions/DonationInterface/modules (added) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/modules/iframe.liberator.js
@@ -0,0 +1,3 @@
 2+if (top.frames.length!=0){
 3+ top.location=self.document.location;
 4+}
\ No newline at end of file
Property changes on: trunk/extensions/DonationInterface/modules/iframe.liberator.js
___________________________________________________________________
Added: svn:eol-style
15 + native
Index: trunk/extensions/DonationInterface/modules/jquery.donationInterface.js
@@ -0,0 +1,214 @@
 2+/**
 3+ * Turns any form with the bare minimum "appropriate" fields into a form that
 4+ * can get a donor to a gateway with no interstitial page.
 5+ * To use:
 6+ * *) Install the ContributionTracking Extension.
 7+ * *) Include this module on a page.
 8+ * *) On that page, create a form that contains (at least) the fields
 9+ * required by ApiContributionTracking.
 10+ * *) Make sure that form's submit button has a unique ID.
 11+ * *) Assign that button the class of "ajax_me".
 12+ *
 13+ * @author Katie Horn <khorn@wikimedia.org>
 14+ */
 15+
 16+( function( $ ) {
 17+
 18+ /**
 19+ * Binds the onclick function to everything with a class of "ajax_me".
 20+ */
 21+ $.bindAjaxControls = function(){
 22+ $(".ajax_me:disabled").removeAttr("disabled");
 23+ $(".ajax_me").click(function() {
 24+ this.disabled = true;
 25+ $.goAjax(this.id);
 26+ return false; //prevent regular form submission.
 27+ //TODO: Think about the button disabling and enabling.
 28+ //TODO: also think about a barber pole. That would go here.
 29+ });
 30+ //$("form")
 31+ }
 32+
 33+ /**
 34+ * Turns the first parent form from the passing object, to an object we can
 35+ * pass to the API.
 36+ * Takes the button ID in string form.
 37+ */
 38+ $.prepareXML = function(buttonID){
 39+ buttonID = "#" + buttonID;
 40+ var form = $(buttonID).parents("form:first");
 41+ var xmlnode = $("#xml_structure");
 42+ var xml = $("#xml_structure").html();
 43+
 44+ delete form.attr( 'action' );
 45+ delete form.attr( 'method' );
 46+
 47+
 48+ //window.alert(xml);
 49+
 50+ //xmlnode.find("merchantid").html("NEW VALUE");
 51+ //window.alert( xmlnode.find("merchantid").html() );
 52+
 53+ var serializedForm = form.serializeArray();
 54+ var sendData = $.stageData(serializedForm);
 55+
 56+ //TODO: Yeah, this works, but... grow up.
 57+// for (key in sendData){
 58+// if(xml.indexOf("@" + key) > 0){
 59+// xml = xml.replace("@" + key, sendData[key]);
 60+// //finalObj[serializedForm[key]['name']] = serializedForm[key]['value'];
 61+// }
 62+// }
 63+
 64+ //Wow. The next business works. Crizzy.
 65+
 66+ $.each(xmlnode.find("order").children() , function (index) {
 67+ var keyname = $(this).text().replace("@", "");
 68+ if (sendData[keyname]){
 69+ $(this).html(sendData[keyname]);
 70+ } else {
 71+ $(this).remove();
 72+ }
 73+ });
 74+ $.each(xmlnode.find("payment").children() , function (index) {
 75+ var keyname = $(this).text().replace("@", "");
 76+ if (sendData[keyname]){
 77+ $(this).html(sendData[keyname]);
 78+ } else {
 79+ $(this).remove();
 80+ }
 81+ });
 82+
 83+
 84+ //xml = $("#xml_structure").find("request").html();
 85+ xml = $("#xml_structure").html();
 86+ window.alert(xml);
 87+ return xml;
 88+ }
 89+
 90+ $.stageData = function(serializedForm) {
 91+ var finalObj = {};
 92+
 93+ for (key in serializedForm){
 94+ if(serializedForm[key]['value'] != ""){
 95+ finalObj[serializedForm[key]['name']] = serializedForm[key]['value'];
 96+ }
 97+ }
 98+
 99+ if (finalObj['emailAdd']){
 100+ finalObj['email'] = finalObj['emailAdd'];
 101+ delete finalObj['emailAdd'];
 102+ }
 103+
 104+ finalObj['amount'] = finalObj['amount'] * 100;
 105+ //do the rest of the staging here.
 106+
 107+ $.debugPostObjectWithAlert(finalObj);
 108+
 109+ return finalObj;
 110+ }
 111+
 112+ $(document).ajaxError(function(event, request, settings, thrown){
 113+ var display = '';
 114+ for (key in event){
 115+ display += "event " + key + " : " + event[key] + "\r\n";
 116+ }
 117+ for (key in event['data']){
 118+ display += "event data " + key + " : " + event[key] + "\r\n";
 119+ }
 120+ for (key in request){
 121+ display += "request " + key + " : " + event[key] + "\r\n";
 122+ }
 123+ for (key in settings){
 124+ display += "settings " + key + " : " + event[key] + "\r\n";
 125+ }
 126+ for (key in thrown){
 127+ display += "thrown " + key + " : " + event[key] + "\r\n";
 128+ }
 129+ window.alert("Ajax Error!\r\n" + display);
 130+ });
 131+
 132+ $.makeAndPostForm = function (postData){
 133+ if ($('#hideyform').length){
 134+ $('#hideyform').empty(); //just in case something is already hiding in the hideyform.
 135+ } else {
 136+ $('<div id="hideyform"></div>').appendTo('body');
 137+ }
 138+ $('<form id="immediate_repost" action="https://ps.gcsip.nl/wdl/wdl" method="POST"></form>').appendTo('#hideyform');
 139+ $('<input type="hidden" id="xml" name="xml" value="' + postData +'">').appendTo('#immediate_repost');
 140+ $('#immediate_repost').submit();
 141+ window.alert("Form Submitted! Go look...");
 142+ }
 143+
 144+
 145+ /**
 146+ * Sends the formatted ajax request to the API, turns the result into a
 147+ * hidden form, and immediately posts that form on return.
 148+ * Takes the button ID in string form.
 149+ */
 150+ $.goAjax = function(buttonID) {
 151+
 152+ var postData = $.prepareXML(buttonID);
 153+ //postData.action = "contributiontracking";
 154+ $.makeAndPostForm(postData);
 155+ return false;
 156+
 157+
 158+ var processAjaxReturn = function(data, status){
 159+ //TODO: Improve the language of the success and error dialogs.
 160+
 161+ window.alert("Return! " + data);
 162+
 163+ if(status != "success"){
 164+ window.alert("Status: " + status);
 165+ $(buttonID).removeAttr("disabled");
 166+ $(".ajax_me:disabled").removeAttr("disabled");
 167+ return;
 168+ }
 169+
 170+ if(data["error"]){
 171+ //TODO: localization. And i18n. And stuff.
 172+ window.alert("The following error has occurred:\r\n" + data["error"]["info"]);
 173+ $(buttonID).removeAttr("disabled");
 174+ $(".ajax_me:disabled").removeAttr("disabled");
 175+ return;
 176+ }
 177+
 178+ if ($('#hideyform').length){
 179+ $('#hideyform').empty(); //just in case something is already hiding in the hideyform.
 180+ } else {
 181+ $('<div id="hideyform"></div>').appendTo('body');
 182+ }
 183+ $('<form id="immediate_repost" action="' + data["returns"]["action"]["url"] + '"></form>').appendTo('#hideyform');
 184+ for (key in data["returns"]["fields"]) {
 185+ $('<input type="hidden" id="' + key +'" name="' + key +'" value="' + data["returns"]["fields"][key] +'">').appendTo('#immediate_repost');
 186+ }
 187+ $('#immediate_repost').submit();
 188+
 189+ }
 190+
 191+// $.post(
 192+// //mw.config.get('wgScriptPath') + '/api.php',
 193+// 'https://ps.gcsip.nl/wdl/wdl',
 194+// //'http://ps.gcsip.nl/wdl/wdl',
 195+// //'http://www.katiehorn.com/nonsense/',
 196+// postData,
 197+// processAjaxReturn,
 198+// 'xml');
 199+ }
 200+
 201+ /**
 202+ * Just for easy debugging. Should not actually be called anywhere.
 203+ * TODO: Take this out when we know we're done here.
 204+ */
 205+ $.debugPostObjectWithAlert = function(object){
 206+ var contents = "";
 207+ for (key in object){
 208+ contents += key + " = " + object[key] + "\r\n";
 209+ }
 210+ window.alert(contents);
 211+ }
 212+
 213+} )( jQuery );
 214+
 215+$.bindAjaxControls();
\ No newline at end of file
Property changes on: trunk/extensions/DonationInterface/modules/jquery.donationInterface.js
___________________________________________________________________
Added: svn:eol-style
1216 + native
Index: trunk/extensions/DonationInterface/modules/skinOverride.css
@@ -0,0 +1,15 @@
 2+#left-navigation {
 3+ display: none !important;
 4+}
 5+#right-navigation {
 6+ display: none !important;
 7+}
 8+#p-search {
 9+ display: none !important;
 10+}
 11+#mw-panel div.portal {
 12+ display: none !important;
 13+}
 14+body.ltr #footer #footer-places {
 15+ display: none !important;
 16+}

Status & tagging log