Skip to content

Commit

Permalink
Merge pull request #149 from ba-st/improve-temporary-disable
Browse files Browse the repository at this point in the history
Improved behavior for temorarily disabling command.
  • Loading branch information
gcotelli authored Sep 9, 2019
2 parents f7238db + bef68c4 commit fcdc80c
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 39 deletions.
2 changes: 1 addition & 1 deletion source/BaselineOfWillow/BaselineOfWillow.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BaselineOfWillow >> projectClass [
BaselineOfWillow >> setUpDependencies: spec [

spec
baseline: 'Seaside3' with: [ spec repository: 'github://SeasideSt/Seaside:v3.3.3/repository' ];
baseline: 'Seaside3' with: [ spec repository: 'github://SeasideSt/Seaside:v3.3.x/repository' ];
project: 'Seaside3-JQuery' copyFrom: 'Seaside3' with: [ spec loads: #('Core' 'Javascript' 'JQuery') ].

spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,12 @@ CombinedWebInteractionInterpreterTest >> testTemporarilyDisableAndTransformInto
interpreter temporarilyDisableAndTransform: textInput into: 'Loading...'.
canvas
render: okButton;
render: cancelButton ].
render: cancelButton
].
self
assert: html
equals:
'<input id="15" type="text"/><button id="button-id2" type="button">Ok</button><button id="button-id4" type="button">Cancel</button><script type="text/javascript">$("#button-id2").click(function(event){disabledComponent=$("#15").html();$("#15").addClass("willow-disabled-component").attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)},"url":"/","data":"1"})});$("#button-id4").click(function(event){disabledComponent=$("#15").html();$("#15").addClass("willow-disabled-component").attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)},"url":"/","data":"3"})});</script>'
'<input id="15" type="text"/><button id="button-id2" type="button">Ok</button><button id="button-id4" type="button">Cancel</button><script type="text/javascript">$("#button-id2").click(function(event){var componentToDisable=$("#15");if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))},"url":"/","data":"1"})}});$("#button-id4").click(function(event){var componentToDisable=$("#15");if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))},"url":"/","data":"3"})}});</script>'
]

{ #category : #'tests-Configuring-DOM' }
Expand All @@ -817,11 +818,12 @@ CombinedWebInteractionInterpreterTest >> testTemporarilyDisableAndTransformSelfI
interpreter temporarilyDisableAndTransformInto: 'Loading...'.
canvas
render: okButton;
render: cancelButton ].
render: cancelButton
].
self
assert: html
equals:
'<button id="button-id2" type="button">Ok</button><button id="button-id4" type="button">Cancel</button><script type="text/javascript">$("#button-id2").click(function(event){disabledComponent=$(this).html();$(this).addClass("willow-disabled-component").attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)},"url":"/","data":"1"})});$("#button-id4").click(function(event){disabledComponent=$(this).html();$(this).addClass("willow-disabled-component").attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)},"url":"/","data":"3"})});</script>'
'<button id="button-id2" type="button">Ok</button><button id="button-id4" type="button">Cancel</button><script type="text/javascript">$("#button-id2").click(function(event){var componentToDisable=$(this);if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))},"url":"/","data":"1"})}});$("#button-id4").click(function(event){var componentToDisable=$(this);if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))},"url":"/","data":"3"})}});</script>'
]

{ #category : #'tests-Configuring - CSS' }
Expand Down
16 changes: 10 additions & 6 deletions source/Willow-Tests/TemporarilyDisablingCommandTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ TemporarilyDisablingCommandTest >> testPriorityActions [

| command html |

command := TemporarilyDisablingCommand transformingCurrentViewInto: [ :canvas | canvas span apply: [ :span | span addClass loading ] ].
command := TemporarilyDisablingCommand
transformingCurrentViewInto: [ :canvas | canvas span apply: [ :span | span addClass loading ] ].
html := self
renderUsing: [ :canvas |
| asynchronousCall anchor |
Expand All @@ -33,12 +34,13 @@ TemporarilyDisablingCommandTest >> testPriorityActions [
command priorityActions do: [ :action | action value: asynchronousCall value: canvas ].
anchor := canvas anchor.
canvas ensureIdFor: anchor.
anchor script: (canvas jQuery this onClick: asynchronousCall) ].
anchor script: ( canvas jQuery this onClick: asynchronousCall )
].

self
assert: html
equals:
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){$.ajax({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)}})});</script>'
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("<span class=\"willow-loading\"></span>");$.ajax({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))}})}});</script>'
]

{ #category : #'tests-testing' }
Expand All @@ -52,7 +54,8 @@ TemporarilyDisablingCommandTest >> testServerIndependentActions [

| command html |

command := TemporarilyDisablingCommand transformingCurrentViewInto: [ :canvas | canvas span apply: [ :span | span addClass loading ] ].
command := TemporarilyDisablingCommand
transformingCurrentViewInto: [ :canvas | canvas span apply: [ :span | span addClass loading ] ].
html := self
renderUsing: [ :canvas |
| script anchor |
Expand All @@ -61,10 +64,11 @@ TemporarilyDisablingCommandTest >> testServerIndependentActions [
command serverIndependentActions do: [ :action | action value: script value: canvas ].
anchor := canvas anchor.
canvas ensureIdFor: anchor.
anchor script: (canvas jQuery this onClick: script) ].
anchor script: ( canvas jQuery this onClick: script )
].

self
assert: html
equals:
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){disabledComponent=$(this).html();$(this).addClass("willow-disabled-component").attr("disabled",true).html("<span class=\"willow-loading\"></span>")});</script>'
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){var componentToDisable=$(this)});</script>'
]
10 changes: 6 additions & 4 deletions source/Willow-Tests/WebInteractionInterpreterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,13 @@ WebInteractionInterpreterTest >> testTemporarilyDisableAndTransformInto [
textInput := canvas textInput.
textInput id: id.
interpreter temporarilyDisableAndTransform: textInput into: 'Loading...'.
interpreter applyTo: textInput on: canvas ].
interpreter applyTo: textInput on: canvas
].

self
assert: html
equals:
'<input id="15" type="text"/><script type="text/javascript">$("#15").change(function(event){disabledComponent=$("#15").html();$("#15").addClass("willow-disabled-component").attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)},"url":"/","data":"1"})});</script>'
'<input id="15" type="text"/><script type="text/javascript">$("#15").change(function(event){var componentToDisable=$("#15");if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))},"url":"/","data":"1"})}});</script>'
]

{ #category : #'tests - Configuring - DOM' }
Expand All @@ -833,12 +834,13 @@ WebInteractionInterpreterTest >> testTemporarilyDisableAndTransformSelfInto [
textInput := canvas textInput.
textInput id: id.
interpreter temporarilyDisableAndTransformInto: 'Loading...'.
interpreter applyTo: textInput on: canvas ].
interpreter applyTo: textInput on: canvas
].

self
assert: html
equals:
'<input id="15" type="text"/><script type="text/javascript">$("#15").change(function(event){disabledComponent=$(this).html();$(this).addClass("willow-disabled-component").attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){$(".willow-disabled-component").attr("disabled",false).removeClass("willow-disabled-component").html(disabledComponent)},"url":"/","data":"1"})});</script>'
'<input id="15" type="text"/><script type="text/javascript">$("#15").change(function(event){var componentToDisable=$(this);if(componentToDisable.attr("data-willow-events-disabled")!=="disabled"){componentToDisable.attr("data-willow-events-disabled","disabled").addClass("willow-disabled-component").attr("data-original-html",componentToDisable.html()).attr("disabled",true).html("Loading...");Willow.callServer({"complete":function(){componentToDisable.removeAttr("data-willow-events-disabled").attr("disabled",false).removeClass("willow-disabled-component").html(componentToDisable.attr("data-original-html"))},"url":"/","data":"1"})}});</script>'
]

{ #category : #'tests - Configuring - CSS' }
Expand Down
16 changes: 16 additions & 0 deletions source/Willow-Tests/WillowJavascriptTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Class {
#name : #WillowJavascriptTest,
#superclass : #JSObjectTest,
#category : #'Willow-Tests-WebInteraction'
}

{ #category : #tests }
WillowJavascriptTest >> testJSConcatenateBefore [

| jsObject |

jsObject := ( ( JSStream this alias: 'theVariable' ) call: 'doIt' )
addDecoration: ( JSConcatenateBefore on: ( JSStream this assignTo: 'theVariable' ) ).

self assert: jsObject equals: 'theVariable=this;theVariable.doIt()'
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ WillowNamespaceFileMetadataLibraryTest >> testDeployFiles [

self
assertFileDeploymentOf: WillowNamespaceFileMetadataLibrary default deployFiles
createsAsFolders: #('willow-8.0.1' 'willow-8.0.1/js')
andFileContentsMatching: {('willow-8.0.1/js/willow.js' -> 'd01dced3b8eed675fe45b1f8a3cb3470c730150b')}
createsAsFolders:
{'willow-8.0.1'.
( 'willow-8.0.1<1s>js' expandMacrosWith: GRPlatform current pathSeparator )}
andFileContentsMatching:
{( ( 'willow-8.0.1<1s>js/willow.js' expandMacrosWith: GRPlatform current pathSeparator )
-> 'd01dced3b8eed675fe45b1f8a3cb3470c730150b' )}
]

{ #category : #tests }
Expand Down
14 changes: 14 additions & 0 deletions source/Willow/JSConcatenateBefore.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Class {
#name : #JSConcatenateBefore,
#superclass : #JSStatement,
#category : #'Willow-WebInteraction'
}

{ #category : #printing }
JSConcatenateBefore >> javascriptContentOn: aStream [

aStream
javascript: self statement;
nextPut: $;.
super javascriptContentOn: aStream
]
95 changes: 73 additions & 22 deletions source/Willow/TemporarilyDisablingCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,64 @@ Class {
#category : #'Willow-WebInteraction'
}

{ #category : #'Instance Creation' }
{ #category : #accessing }
TemporarilyDisablingCommand class >> componentToDisableVariableName [

^ 'componentToDisable'
]

{ #category : #'instance creation' }
TemporarilyDisablingCommand class >> transforming: anIdentifieView into: aViewWhileDisabled [

^ self
transformingComponentMatching: [ :canvas |
anIdentifieView identifyIn: canvas.
canvas jQuery id: anIdentifieView identifier ]
canvas jQuery id: anIdentifieView identifier
]
into: aViewWhileDisabled
]

{ #category : #'Instance Creation' }
{ #category : #'instance creation' }
TemporarilyDisablingCommand class >> transformingComponentMatching: aComponentProvider into: aViewWhileDisabled [

^self new initializeTransformingComponentMatching: aComponentProvider into: aViewWhileDisabled
^ self new initializeTransformingComponentMatching: aComponentProvider into: aViewWhileDisabled
]

{ #category : #'Instance Creation' }
{ #category : #'instance creation' }
TemporarilyDisablingCommand class >> transformingCurrentViewInto: aViewWhileDisabled [

^self transformingComponentMatching: [:canvas | canvas jQuery this] into: aViewWhileDisabled
^ self transformingComponentMatching: [ :canvas | canvas jQuery this ] into: aViewWhileDisabled
]

{ #category : #private }
TemporarilyDisablingCommand >> areEventsEnabledOn: aCanvas [

^ ( ( self componentToDisableVariableOn: aCanvas ) attributeAt: self eventsDisabledAttributeName )
notIdenticalTo: 'disabled'
]

{ #category : #accessing }
TemporarilyDisablingCommand >> clientIndependentActions [

^#()
^ #()
]

{ #category : #private }
TemporarilyDisablingCommand >> componentToDisableOn: aCanvas [

^componentProvider value: aCanvas
^ componentProvider value: aCanvas
]

{ #category : #private }
TemporarilyDisablingCommand >> componentToDisableVariableName [

^ self class componentToDisableVariableName
]

{ #category : #private }
TemporarilyDisablingCommand >> componentToDisableVariableOn: aCanvas [

^ aCanvas jQuery new alias: self componentToDisableVariableName
]

{ #category : #private }
Expand All @@ -52,9 +78,9 @@ TemporarilyDisablingCommand >> disabledAttributeName [
]

{ #category : #private }
TemporarilyDisablingCommand >> disabledComponentVariableName [
TemporarilyDisablingCommand >> eventsDisabledAttributeName [

^'disabledComponent'
^ 'data-willow-events-disabled'
]

{ #category : #initialization }
Expand All @@ -67,7 +93,13 @@ TemporarilyDisablingCommand >> initializeTransformingComponentMatching: aCompone
{ #category : #accessing }
TemporarilyDisablingCommand >> modelLoadingActions [

^#()
^ #()
]

{ #category : #private }
TemporarilyDisablingCommand >> originalContentAttributeName [

^ 'data-original-html'
]

{ #category : #accessing }
Expand All @@ -76,11 +108,10 @@ TemporarilyDisablingCommand >> priorityActions [
^ Array
with: [ :anAsynchronousCall :aCanvas |
anAsynchronousCall
onComplete:
((aCanvas jQuery class: Classification >> #disabledComponent)
attributeAt: self disabledAttributeName put: false;
removeClass: Classification >> #disabledComponent;
call: 'html' with: (aCanvas jQuery alias: self disabledComponentVariableName)) ]
addDecoration: ( JSConcatenateBefore on: ( self stepsBeforeServelCallOn: aCanvas ) ).
anAsynchronousCall condition: ( self areEventsEnabledOn: aCanvas ).
anAsynchronousCall onComplete: ( self stepsAfterServerCallOn: aCanvas )
]
]

{ #category : #testing }
Expand All @@ -94,11 +125,31 @@ TemporarilyDisablingCommand >> serverIndependentActions [

^ Array
with: [ :script :canvas |
script << ((self componentToDisableOn: canvas) html assignTo: self disabledComponentVariableName).
script
<<
((self componentToDisableOn: canvas)
addClass: Classification >> #disabledComponent;
attributeAt: self disabledAttributeName put: true;
html: viewWhileDisabled) ]
<< ( ( self componentToDisableOn: canvas ) assignLocalTo: self componentToDisableVariableName )
]
]

{ #category : #private }
TemporarilyDisablingCommand >> stepsAfterServerCallOn: aCanvas [

^ ( self componentToDisableVariableOn: aCanvas )
removeAttribute: self eventsDisabledAttributeName;
attributeAt: self disabledAttributeName put: false;
removeClass: Willow classification >> #disabledComponent;
call: 'html'
with:
( ( self componentToDisableVariableOn: aCanvas ) attributeAt: self originalContentAttributeName )
]

{ #category : #private }
TemporarilyDisablingCommand >> stepsBeforeServelCallOn: aCanvas [

^ ( self componentToDisableVariableOn: aCanvas )
attributeAt: self eventsDisabledAttributeName put: 'disabled';
addClass: Willow classification >> #disabledComponent;
attributeAt: self originalContentAttributeName
put: ( self componentToDisableVariableOn: aCanvas ) html;
attributeAt: self disabledAttributeName put: true;
html: viewWhileDisabled
]

0 comments on commit fcdc80c

Please sign in to comment.