Bläddra i källkod

Add useful Ajax callbacks + Block asString

Laurent Laffont 12 år sedan
förälder
incheckning
b2039d5043
6 ändrade filer med 124 tillägg och 9 borttagningar
  1. 32 2
      js/JQuery.deploy.js
  2. 32 2
      js/JQuery.js
  3. 15 0
      js/Kernel.deploy.js
  4. 15 0
      js/Kernel.js
  5. 17 5
      st/JQuery.st
  6. 13 0
      st/Kernel.st

+ 32 - 2
js/JQuery.deploy.js

@@ -883,12 +883,42 @@ smalltalk.addMethod(
 '_onSuccessDo_',
 smalltalk.method({
 selector: 'onSuccessDo:',
-category: 'accessing',
+category: 'callbacks',
 fn: function (aBlock){
 var self=this;
 smalltalk.send(self, "_at_put_", ["success", aBlock]);
 return self;},
-source: unescape('onSuccessDo%3A%20aBlock%0A%09%22Set%20action%20to%20execute%20when%20Ajax%20request%20is%20successful.%20Pass%20received%20data%20as%20block%20argument%22%0A%09self%20at%3A%20%27success%27%20put%3A%20aBlock'),
+source: unescape('onSuccessDo%3A%20aBlock%0A%09%22Set%20action%20to%20execute%20when%20Ajax%20request%20is%20successful.%20Pass%20received%20data%20as%20block%20argument.%20Block%20arguments%3A%20data%2C%20textStatus%2C%20jqXHR%22%0A%09self%20at%3A%20%27success%27%20put%3A%20aBlock'),
+messageSends: ["at:put:"],
+referencedClasses: []
+}),
+smalltalk.Ajax);
+
+smalltalk.addMethod(
+'_onCompleteDo_',
+smalltalk.method({
+selector: 'onCompleteDo:',
+category: 'callbacks',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self, "_at_put_", ["complete", aBlock]);
+return self;},
+source: unescape('onCompleteDo%3A%20aBlock%0A%09%22A%20block%20to%20be%20called%20when%20the%20request%20finishes%20%28after%20success%20and%20error%20callbacks%20are%20executed%29.%20Block%20arguments%3A%20jqXHR%2C%20textStatus%22%0A%09self%20at%3A%20%27complete%27%20put%3A%20aBlock'),
+messageSends: ["at:put:"],
+referencedClasses: []
+}),
+smalltalk.Ajax);
+
+smalltalk.addMethod(
+'_onErrorDo_',
+smalltalk.method({
+selector: 'onErrorDo:',
+category: 'callbacks',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self, "_at_put_", ["error", aBlock]);
+return self;},
+source: unescape('onErrorDo%3A%20aBlock%0A%09%22A%20block%20to%20be%20called%20if%20the%20request%20fails.Block%20arguments%3A%20jqXHR%2C%20textStatus%2C%20errorThrown%22%0A%09self%20at%3A%20%27error%27%20put%3A%20aBlock'),
 messageSends: ["at:put:"],
 referencedClasses: []
 }),

+ 32 - 2
js/JQuery.js

@@ -883,12 +883,42 @@ smalltalk.addMethod(
 '_onSuccessDo_',
 smalltalk.method({
 selector: 'onSuccessDo:',
-category: 'accessing',
+category: 'callbacks',
 fn: function (aBlock){
 var self=this;
 smalltalk.send(self, "_at_put_", ["success", aBlock]);
 return self;},
-source: unescape('onSuccessDo%3A%20aBlock%0A%09%22Set%20action%20to%20execute%20when%20Ajax%20request%20is%20successful.%20Pass%20received%20data%20as%20block%20argument%22%0A%09self%20at%3A%20%27success%27%20put%3A%20aBlock'),
+source: unescape('onSuccessDo%3A%20aBlock%0A%09%22Set%20action%20to%20execute%20when%20Ajax%20request%20is%20successful.%20Pass%20received%20data%20as%20block%20argument.%20Block%20arguments%3A%20data%2C%20textStatus%2C%20jqXHR%22%0A%09self%20at%3A%20%27success%27%20put%3A%20aBlock'),
+messageSends: ["at:put:"],
+referencedClasses: []
+}),
+smalltalk.Ajax);
+
+smalltalk.addMethod(
+'_onCompleteDo_',
+smalltalk.method({
+selector: 'onCompleteDo:',
+category: 'callbacks',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self, "_at_put_", ["complete", aBlock]);
+return self;},
+source: unescape('onCompleteDo%3A%20aBlock%0A%09%22A%20block%20to%20be%20called%20when%20the%20request%20finishes%20%28after%20success%20and%20error%20callbacks%20are%20executed%29.%20Block%20arguments%3A%20jqXHR%2C%20textStatus%22%0A%09self%20at%3A%20%27complete%27%20put%3A%20aBlock'),
+messageSends: ["at:put:"],
+referencedClasses: []
+}),
+smalltalk.Ajax);
+
+smalltalk.addMethod(
+'_onErrorDo_',
+smalltalk.method({
+selector: 'onErrorDo:',
+category: 'callbacks',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self, "_at_put_", ["error", aBlock]);
+return self;},
+source: unescape('onErrorDo%3A%20aBlock%0A%09%22A%20block%20to%20be%20called%20if%20the%20request%20fails.Block%20arguments%3A%20jqXHR%2C%20textStatus%2C%20errorThrown%22%0A%09self%20at%3A%20%27error%27%20put%3A%20aBlock'),
 messageSends: ["at:put:"],
 referencedClasses: []
 }),

+ 15 - 0
js/Kernel.deploy.js

@@ -2107,6 +2107,21 @@ referencedClasses: []
 }),
 smalltalk.BlockClosure);
 
+smalltalk.addMethod(
+'_printString',
+smalltalk.method({
+selector: 'printString',
+category: 'printing',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.String, "_streamContents_", [(function(aStream){return (function($rec){smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(self, "_printString", [], smalltalk.Object)]);smalltalk.send($rec, "_nextPutAll_", [unescape("%28")]);smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(self, "_compiledSource", [])]);smalltalk.send($rec, "_nextPutAll_", [unescape("%29")]);return smalltalk.send($rec, "_cr", []);})(aStream);})]);
+return self;},
+source: unescape('printString%0A%09%5E%20String%20streamContents%3A%20%5B%3AaStream%7C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20aStream%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20super%20printString%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20%27%28%27%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20self%20compiledSource%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20%27%29%27%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09cr.%0A%20%20%20%20%20%20%20%20%20%20%20%5D'),
+messageSends: ["streamContents:", "nextPutAll:", "printString", "compiledSource", "cr"],
+referencedClasses: [smalltalk.String]
+}),
+smalltalk.BlockClosure);
+
 
 
 smalltalk.addClass('Boolean', smalltalk.Object, [], 'Kernel');

+ 15 - 0
js/Kernel.js

@@ -2107,6 +2107,21 @@ referencedClasses: []
 }),
 smalltalk.BlockClosure);
 
+smalltalk.addMethod(
+'_printString',
+smalltalk.method({
+selector: 'printString',
+category: 'printing',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.String, "_streamContents_", [(function(aStream){return (function($rec){smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(self, "_printString", [], smalltalk.Object)]);smalltalk.send($rec, "_nextPutAll_", [unescape("%28")]);smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(self, "_compiledSource", [])]);smalltalk.send($rec, "_nextPutAll_", [unescape("%29")]);return smalltalk.send($rec, "_cr", []);})(aStream);})]);
+return self;},
+source: unescape('printString%0A%09%5E%20String%20streamContents%3A%20%5B%3AaStream%7C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20aStream%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20super%20printString%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20%27%28%27%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20self%20compiledSource%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09nextPutAll%3A%20%27%29%27%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%09cr.%0A%20%20%20%20%20%20%20%20%20%20%20%5D'),
+messageSends: ["streamContents:", "nextPutAll:", "printString", "compiledSource", "cr"],
+referencedClasses: [smalltalk.String]
+}),
+smalltalk.BlockClosure);
+
 
 
 smalltalk.addClass('Boolean', smalltalk.Object, [], 'Kernel');

+ 17 - 5
st/JQuery.st

@@ -291,11 +291,6 @@ url
 
 url: aString
     self at: 'url' put: aString
-!
-
-onSuccessDo: aBlock
-	"Set action to execute when Ajax request is successful. Pass received data as block argument"
-	self at: 'success' put: aBlock
 ! !
 
 !Ajax methodsFor: 'actions'!
@@ -304,6 +299,23 @@ send
     <jQuery.ajax(self['@settings'])>
 ! !
 
+!Ajax methodsFor: 'callbacks'!
+
+onSuccessDo: aBlock
+	"Set action to execute when Ajax request is successful. Pass received data as block argument. Block arguments: data, textStatus, jqXHR"
+	self at: 'success' put: aBlock
+!
+
+onCompleteDo: aBlock
+	"A block to be called when the request finishes (after success and error callbacks are executed). Block arguments: jqXHR, textStatus"
+	self at: 'complete' put: aBlock
+!
+
+onErrorDo: aBlock
+	"A block to be called if the request fails.Block arguments: jqXHR, textStatus, errorThrown"
+	self at: 'error' put: aBlock
+! !
+
 !Ajax methodsFor: 'initialization'!
 
 initialize

+ 13 - 0
st/Kernel.st

@@ -719,6 +719,19 @@ valueWithPossibleArguments: aCollection
 	<return self.apply(null, aCollection);>
 ! !
 
+!BlockClosure methodsFor: 'printing'!
+
+printString
+	^ String streamContents: [:aStream| 
+                                  aStream 
+                                  	nextPutAll: super printString;
+                                  	nextPutAll: '(';
+                                  	nextPutAll: self compiledSource;
+                                  	nextPutAll: ')';
+                                  	cr.
+           ]
+! !
+
 !BlockClosure methodsFor: 'timeout/interval'!
 
 valueWithTimeout: aNumber