Skip to content

Commit

Permalink
Simplified typeahead command
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Sep 14, 2017
1 parent b2a377d commit a787ea0
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 84 deletions.
Expand Up @@ -3,9 +3,11 @@ testApplyToOn

| html |

html := self apply: (BootstrapTypeaheadCommand searchingWith: [ :searchTerm | #(1 2 3 4) ] withSelectionDo: [ :selectedNumber | ]) toComponentDefinedBy: [ :canvas | canvas textInput ].
html := self
apply: (BootstrapTypeaheadCommand searchingWith: [ :searchTerm | #(1 2 3 4) ] withSelectionDo: [ :selectedNumber | ])
toComponentDefinedBy: [ :canvas | canvas textInput ].

self
assert: html
equals:
'<input id="id5" type="text"/><script type="text/javascript">$("#id5").typeahead({"source":function(searchTerm,response){$.getJSON("/",["1","2="+encodeURIComponent(searchTerm)].join("&"),function(data,status){response(data)})},"updater":function(item){return item.index},"afterSelect":function(activeItem){$.ajax({"url":"/","data":["3","4="+encodeURIComponent(activeItem)].join("&"),"dataType":"script"})}});</script>'
'<input id="id5" type="text"/><script type="text/javascript">$("#id5").typeahead({"source":function(searchTerm,response){$.getJSON("/",["1","2="+encodeURIComponent(searchTerm)].join("&"),function(data,status){response(data)})},"updater":function(item){return item},"afterSelect":function(activeItem){$.ajax({"url":"/","data":["3","4="+encodeURIComponent(activeItem.index)].join("&"),"dataType":"script"})}});</script>'
Expand Up @@ -10,4 +10,4 @@ testApplyToOnWithConfiguration
self
assert: html
equals:
'<input id="id5" type="text"/><script type="text/javascript">$("#id5").typeahead({"source":function(searchTerm,response){$.getJSON("/",["1","2="+encodeURIComponent(searchTerm)].join("&"),function(data,status){response(data)})},"updater":function(item){return item.index},"afterSelect":function(activeItem){$.ajax({"url":"/","data":["3","4="+encodeURIComponent(activeItem)].join("&"),"dataType":"script"})},"minLength":5});</script>'
'<input id="id5" type="text"/><script type="text/javascript">$("#id5").typeahead({"source":function(searchTerm,response){$.getJSON("/",["1","2="+encodeURIComponent(searchTerm)].join("&"),function(data,status){response(data)})},"updater":function(item){return item},"afterSelect":function(activeItem){$.ajax({"url":"/","data":["3","4="+encodeURIComponent(activeItem.index)].join("&"),"dataType":"script"})},"minLength":5});</script>'

This file was deleted.

@@ -1,8 +1,7 @@
{
"instance" : {
"testApplyToOnWithRendering" : "GabrielOmarCotelli 9/13/2017 15:34",
"testApplyToOn" : "GabrielOmarCotelli 9/13/2017 15:25",
"testApplyToOnWithConfiguration" : "GabrielOmarCotelli 9/13/2017 15:28",
"testApplyToOn" : "GabrielOmarCotelli 9/14/2017 10:09",
"testApplyToOnWithConfiguration" : "GabrielOmarCotelli 9/14/2017 10:10",
"testEvaluateWithUsing" : "GabrielOmarCotelli 9/13/2017 15:42"
},
"class" : { }
Expand Down

Large diffs are not rendered by default.

@@ -1,9 +1,8 @@
Instance Creation
searchingWith: aSearchAction labeledBy: aLabelsBlock withSelectionDo: aSelectionCallback configuredBy: aConfigurationBlock

^ self
searchingWith: aSearchAction
^ self new
initializeSearchingWith: aSearchAction
labeledBy: aLabelsBlock
withSelectionDo: aSelectionCallback
thenRefresh: Optional unused
configuredBy: aConfigurationBlock

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,11 @@
private
afterSelectFunctionEvaluate: aSelectionCallback on: aCanvas

| selectedIndexHolder ajax |

selectedIndexHolder := WAValueHolder new.
ajax := aCanvas jQuery ajax.
ajax
callback: [ :activeItemIndex | selectedIndexHolder contents: activeItemIndex greaseInteger ] value: ((aCanvas jQuery alias: 'activeItem') access: self indexProperty);
script: [ :script | aSelectionCallback value: (searchResults at: selectedIndexHolder contents) ].
^ ajax asFunction: #('activeItem')

This file was deleted.

@@ -1,16 +1,15 @@
initialization
initializeSearchingWith: aSearchAction labeledBy: aLabelsBlock withSelectionDo: aSelectionCallback thenRefresh: anIdentifiedViewOptional configuredBy: aConfigurationBlock
initializeSearchingWith: aSearchAction labeledBy: aLabelsBlock withSelectionDo: aSelectionCallback configuredBy: aConfigurationBlock

searchResults := #().
scriptCommand := ComponentScriptCommand
toExecute: [ :canvas |
| typeahead |

anIdentifiedViewOptional withContentDo: [ :identifiedView | identifiedView identifyIn: canvas ].
typeahead := canvas jQuery this bootstrapTypeahead.
typeahead
source: (self searchWith: aSearchAction labels: aLabelsBlock on: canvas);
updater: self updaterFunction;
afterSelect: (self afterSelectFunctionEvaluate: aSelectionCallback thenRefresh: anIdentifiedViewOptional on: canvas).
afterSelect: (self afterSelectFunctionEvaluate: aSelectionCallback on: canvas).
aConfigurationBlock cull: typeahead cull: canvas.
typeahead ]
@@ -1,8 +1,8 @@
private
updaterFunction
updaterFunction

^ JSFunction new
arguments: #('item');
add: ((JSStream this alias: 'item') access: self indexProperty);
add: (JSStream this alias: 'item');
return: true;
yourself
@@ -1,24 +1,21 @@
{
"instance" : {
"initializeSearchingWith:labeledBy:withSelectionDo:configuredBy:" : "GabrielOmarCotelli 9/14/2017 10:01",
"applyTo:on:" : "GabrielOmarCotelli 9/12/2017 16:45",
"initializeSearchingWith:labeledBy:withSelectionDo:thenRefresh:configuredBy:" : "GabrielOmarCotelli 9/13/2017 15:34",
"afterSelectFunctionEvaluate:thenRefresh:on:" : "GabrielOmarCotelli 9/13/2017 15:15",
"responseFunctionName" : "GabrielOmarCotelli 9/13/2017 15:03",
"evaluate:with:using:" : "GabrielOmarCotelli 9/13/2017 15:07",
"searchTermVariable" : "GabrielOmarCotelli 9/13/2017 15:03",
"indexProperty" : "GabrielOmarCotelli 9/13/2017 15:01",
"searchWith:labels:on:" : "GabrielOmarCotelli 9/13/2017 15:07",
"updaterFunction" : "GabrielOmarCotelli 9/13/2017 15:08",
"responseFunctionName" : "GabrielOmarCotelli 9/13/2017 15:03"
"updaterFunction" : "GabrielOmarCotelli 9/14/2017 10:05",
"afterSelectFunctionEvaluate:on:" : "GabrielOmarCotelli 9/14/2017 10:07"
},
"class" : {
"searchingWith:labeledBy:withSelectionDo:configuredBy:" : "GabrielOmarCotelli 9/13/2017 15:17",
"defaultLabelBlock" : "GabrielOmarCotelli 9/13/2017 15:20",
"searchingWith:labeledBy:withSelectionDo:configuredBy:" : "GabrielOmarCotelli 9/14/2017 10:02",
"searchingWith:withSelectionDo:" : "GabrielOmarCotelli 9/13/2017 15:20",
"searchingWith:labeledBy:withSelectionDo:thenRendering:configuredBy:" : "GabrielOmarCotelli 9/13/2017 15:19",
"defaultLabelBlock" : "GabrielOmarCotelli 9/13/2017 15:20",
"searchingWith:withSelectionDo:configuredBy:" : "GabrielOmarCotelli 9/13/2017 15:21",
"searchingWith:labeledBy:withSelectionDo:" : "GabrielOmarCotelli 9/13/2017 15:21",
"searchingWith:labeledBy:withSelectionDo:thenRefresh:configuredBy:" : "GabrielOmarCotelli 9/13/2017 15:16",
"defaultConfigurationBlock" : "GabrielOmarCotelli 9/13/2017 15:21",
"searchingWith:labeledBy:withSelectionDo:thenRendering:" : "GabrielOmarCotelli 9/13/2017 15:19",
"searchingWith:withSelectionDo:configuredBy:" : "GabrielOmarCotelli 9/13/2017 15:21"
"defaultConfigurationBlock" : "GabrielOmarCotelli 9/13/2017 15:21"
}
}

0 comments on commit a787ea0

Please sign in to comment.