Browse Source

selectValue and optionValue processors

Herbert Vojčík 10 years ago
parent
commit
918be43ba5
2 changed files with 176 additions and 0 deletions
  1. 115 0
      js/Trapped-Processors.js
  2. 61 0
      st/Trapped-Processors.st

+ 115 - 0
js/Trapped-Processors.js

@@ -398,6 +398,27 @@ smalltalk.TrappedProcessorLoopZ);
 
 
 
+smalltalk.addClass('TrappedProcessorOptionValue', smalltalk.TrappedDataExpectingProcessor, [], 'Trapped-Processors');
+smalltalk.TrappedProcessorOptionValue.comment="I set the option value.\x0a\x0aAdditionally, when changed (by toView:),\x0aI ping closest <select> with 'trappedselectreplay' event.";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "toView:",
+category: 'data transformation',
+fn: function (aDataCarrier){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(aDataCarrier)._toTargetValue();
+_st(_st(_st(_st(aDataCarrier)._target())._asJQuery())._closest_("select"))._trigger_("trappedselectreplay");
+return self}, function($ctx1) {$ctx1.fill(self,"toView:",{aDataCarrier:aDataCarrier},smalltalk.TrappedProcessorOptionValue)})},
+args: ["aDataCarrier"],
+source: "toView: aDataCarrier\x0a\x09aDataCarrier toTargetValue.\x0a\x09(aDataCarrier target asJQuery closest: 'select')\x0a\x09\x09trigger: 'trappedselectreplay'",
+messageSends: ["toTargetValue", "trigger:", "closest:", "asJQuery", "target"],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessorOptionValue);
+
+
+
 smalltalk.addClass('TrappedProcessorReplace', smalltalk.TrappedProcessor, ['left', 'right'], 'Trapped-Processors');
 smalltalk.TrappedProcessorReplace.comment="I convert data to string representation and do a regex replace.\x0aI get two parameters, in toView:, first is replaced with second,\x0aand in toModel:, the second is replaced with first.\x0a\x0aI remove leading '^' and ending '$' from the string used as replacement,\x0aso it safe to replace ^to with ^To, for example.\x0a";
 smalltalk.addMethod(
@@ -507,6 +528,62 @@ referencedClasses: []
 smalltalk.TrappedProcessorReplace.klass);
 
 
+smalltalk.addClass('TrappedProcessorSelectValue', smalltalk.TrappedDataExpectingProcessor, [], 'Trapped-Processors');
+smalltalk.TrappedProcessorSelectValue.comment="I bind to select value.\x0a\x0aWhen changed (by toView: or by user),\x0aI remember the selected set.\x0a\x0aWhen pinged by 'trappedselectreplay',\x0aI set the remembered value.\x0a\x0aThis allows to have select-option groups\x0awith later setting of option values\x0a(if those are set via related processor 'optionValue',\x0awhich pings me with 'trappedselectreplay').";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "installToView:toModel:",
+category: 'installation',
+fn: function (aDataCarrier,anotherDataCarrier){
+var self=this;
+var jq,val;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2,$3,$4;
+jq=_st(_st(aDataCarrier)._target())._asJQuery();
+val=_st(jq)._val();
+$ctx1.sendIdx["val"]=1;
+$1=jq;
+_st($1)._data_("trapped.saved.val");
+$ctx1.sendIdx["data:"]=1;
+_st($1)._on_bind_("change",(function(){
+return smalltalk.withContext(function($ctx2) {
+$2=_st(anotherDataCarrier)._copy();
+_st($2)._value_(_st(jq)._val());
+$3=_st($2)._proceed();
+return $3;
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
+$ctx1.sendIdx["on:bind:"]=1;
+$4=_st($1)._on_bind_("trappedselectreplay",(function(){
+return smalltalk.withContext(function($ctx2) {
+return _st(jq)._val_(_st(jq)._data_("trapped.saved.val"));
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"installToView:toModel:",{aDataCarrier:aDataCarrier,anotherDataCarrier:anotherDataCarrier,jq:jq,val:val},smalltalk.TrappedProcessorSelectValue)})},
+args: ["aDataCarrier", "anotherDataCarrier"],
+source: "installToView: aDataCarrier toModel: anotherDataCarrier\x0a\x09| jq val |\x0a\x09jq := aDataCarrier target asJQuery.\x0a\x09val := jq val.\x0a\x09jq\x0a\x09\x09data: 'trapped.saved.val';\x0a\x09\x09on: 'change' bind: [ anotherDataCarrier copy value: jq val; proceed ];\x0a\x09\x09on: 'trappedselectreplay' bind: [ jq val: (jq data: 'trapped.saved.val') ]",
+messageSends: ["asJQuery", "target", "val", "data:", "on:bind:", "value:", "copy", "proceed", "val:"],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessorSelectValue);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "toView:",
+category: 'data transformation',
+fn: function (aDataCarrier){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(aDataCarrier)._toTargetValue();
+_st(_st(_st(aDataCarrier)._target())._asJQuery())._data_put_("trapped.saved.val",_st(aDataCarrier)._value());
+return self}, function($ctx1) {$ctx1.fill(self,"toView:",{aDataCarrier:aDataCarrier},smalltalk.TrappedProcessorSelectValue)})},
+args: ["aDataCarrier"],
+source: "toView: aDataCarrier\x0a\x09aDataCarrier toTargetValue.\x0a\x09aDataCarrier target asJQuery data: 'trapped.saved.val' put: aDataCarrier value",
+messageSends: ["toTargetValue", "data:put:", "asJQuery", "target", "value"],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessorSelectValue);
+
+
+
 smalltalk.addClass('TrappedProcessorSignal', smalltalk.TrappedProcessor, ['selector'], 'Trapped-Processors');
 smalltalk.TrappedProcessorSignal.comment="Instead of writing data directly to model,\x0aI instead modify it by sending a message specified when instantiating me.";
 smalltalk.addMethod(
@@ -1113,6 +1190,25 @@ referencedClasses: ["TrappedProcessorLoopZ"]
 }),
 smalltalk.TrappedProcessor.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "optionValue",
+category: '*Trapped-Processors',
+fn: function (){
+var self=this;
+function $TrappedProcessorOptionValue(){return smalltalk.TrappedProcessorOptionValue||(typeof TrappedProcessorOptionValue=="undefined"?nil:TrappedProcessorOptionValue)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($TrappedProcessorOptionValue())._new();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"optionValue",{},smalltalk.TrappedProcessor.klass)})},
+args: [],
+source: "optionValue\x0a\x09^TrappedProcessorOptionValue new",
+messageSends: ["new"],
+referencedClasses: ["TrappedProcessorOptionValue"]
+}),
+smalltalk.TrappedProcessor.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "path",
@@ -1151,6 +1247,25 @@ referencedClasses: ["TrappedProcessorReplace"]
 }),
 smalltalk.TrappedProcessor.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "selectValue",
+category: '*Trapped-Processors',
+fn: function (){
+var self=this;
+function $TrappedProcessorSelectValue(){return smalltalk.TrappedProcessorSelectValue||(typeof TrappedProcessorSelectValue=="undefined"?nil:TrappedProcessorSelectValue)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($TrappedProcessorSelectValue())._new();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"selectValue",{},smalltalk.TrappedProcessor.klass)})},
+args: [],
+source: "selectValue\x0a\x09^TrappedProcessorSelectValue new",
+messageSends: ["new"],
+referencedClasses: ["TrappedProcessorSelectValue"]
+}),
+smalltalk.TrappedProcessor.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "signal:",

+ 61 - 0
st/Trapped-Processors.st

@@ -202,6 +202,23 @@ toView: aDataCarrier
 	frozen target trapIter: #() after: [ :html | frozen copy target: html root; xontent: xon; proceed ]
 ! !
 
+TrappedDataExpectingProcessor subclass: #TrappedProcessorOptionValue
+	instanceVariableNames: ''
+	package: 'Trapped-Processors'!
+!TrappedProcessorOptionValue commentStamp!
+I set the option value.
+
+Additionally, when changed (by toView:),
+I ping closest <select> with 'trappedselectreplay' event.!
+
+!TrappedProcessorOptionValue methodsFor: 'data transformation'!
+
+toView: aDataCarrier
+	aDataCarrier toTargetValue.
+	(aDataCarrier target asJQuery closest: 'select')
+		trigger: 'trappedselectreplay'
+! !
+
 TrappedProcessor subclass: #TrappedProcessorReplace
 	instanceVariableNames: 'left right'
 	package: 'Trapped-Processors'!
@@ -252,6 +269,42 @@ new: aString with: anotherString
 		yourself
 ! !
 
+TrappedDataExpectingProcessor subclass: #TrappedProcessorSelectValue
+	instanceVariableNames: ''
+	package: 'Trapped-Processors'!
+!TrappedProcessorSelectValue commentStamp!
+I bind to select value.
+
+When changed (by toView: or by user),
+I remember the selected set.
+
+When pinged by 'trappedselectreplay',
+I set the remembered value.
+
+This allows to have select-option groups
+with later setting of option values
+(if those are set via related processor 'optionValue',
+which pings me with 'trappedselectreplay').!
+
+!TrappedProcessorSelectValue methodsFor: 'data transformation'!
+
+toView: aDataCarrier
+	aDataCarrier toTargetValue.
+	aDataCarrier target asJQuery data: 'trapped.saved.val' put: aDataCarrier value
+! !
+
+!TrappedProcessorSelectValue methodsFor: 'installation'!
+
+installToView: aDataCarrier toModel: anotherDataCarrier
+	| jq val |
+	jq := aDataCarrier target asJQuery.
+	val := jq val.
+	jq
+		data: 'trapped.saved.val';
+		on: 'change' bind: [ anotherDataCarrier copy value: jq val; proceed ];
+		on: 'trappedselectreplay' bind: [ jq val: (jq data: 'trapped.saved.val') ]
+! !
+
 TrappedProcessor subclass: #TrappedProcessorSignal
 	instanceVariableNames: 'selector'
 	package: 'Trapped-Processors'!
@@ -477,6 +530,10 @@ loopZ
 	^TrappedProcessorLoopZ new
 !
 
+optionValue
+	^TrappedProcessorOptionValue new
+!
+
 path
 	^TrappedProcessorDescend new
 !
@@ -485,6 +542,10 @@ replace: aString with: anotherString
 	^TrappedProcessorReplace new: aString with: anotherString
 !
 
+selectValue
+	^TrappedProcessorSelectValue new
+!
+
 signal: aString
 	^TrappedProcessorSignal new: aString
 !