@@ -69,6 +69,7 @@ define [
69
69
' ./../models/page'
70
70
' ./../models/phonology'
71
71
' ./../models/search'
72
+ ' ./../models/server'
72
73
' ./../models/source'
73
74
' ./../models/speaker'
74
75
' ./../models/subcorpus'
@@ -89,6 +90,7 @@ define [
89
90
' ./../collections/pages'
90
91
' ./../collections/phonologies'
91
92
' ./../collections/searches'
93
+ ' ./../collections/servers'
92
94
' ./../collections/sources'
93
95
' ./../collections/speakers'
94
96
' ./../collections/subcorpora'
@@ -117,16 +119,16 @@ define [
117
119
ApplicationSettingsModel, CollectionModel, ElicitationMethodModel, FileModel,
118
120
FormModel, LanguageModelModel, LanguageModel, MorphologicalParserModel,
119
121
MorphologyModel, OLDApplicationSettingsModel, OrthographyModel, PageModel,
120
- PhonologyModel, SearchModel, SourceModel, SpeakerModel, SubcorpusModel ,
121
- SyntacticCategoryModel, TagModel, UserModel,
122
+ PhonologyModel, SearchModel, ServerModel, SourceModel, SpeakerModel ,
123
+ SubcorpusModel, SyntacticCategoryModel, TagModel, UserModel,
122
124
123
125
CollectionsCollection, ElicitationMethodsCollection, FilesCollection,
124
126
FormsCollection, LanguageModelsCollection, LanguagesCollection,
125
127
MorphologicalParsersCollection, MorphologiesCollection,
126
128
OrthographiesCollection, OLDApplicationSettingsCollection, PagesCollection,
127
- PhonologiesCollection, SearchesCollection, SourcesCollection ,
128
- SpeakersCollection, SubcorporaCollection, SyntacticCategoriesCollection ,
129
- TagsCollection, UsersCollection,
129
+ PhonologiesCollection, SearchesCollection, ServersCollection ,
130
+ SourcesCollection, SpeakersCollection, SubcorporaCollection ,
131
+ SyntacticCategoriesCollection, TagsCollection, UsersCollection,
130
132
131
133
globals, appTemplate) ->
132
134
@@ -146,6 +148,10 @@ define [
146
148
initialize : (options ) ->
147
149
@ preventParentScroll ()
148
150
@ getApplicationSettings options
151
+ @ fetchServers ()
152
+
153
+ # Continue initialization after fetching servers.json
154
+ initializeContinue : ->
149
155
globals .applicationSettings = @applicationSettings
150
156
@ overrideFieldDBNotificationHooks ()
151
157
@ initializePersistentSubviews ()
@@ -479,6 +485,39 @@ define [
479
485
else
480
486
@applicationSettings = new ApplicationSettingsModel ()
481
487
488
+ # We have fetched the default servers array from the server hosting this
489
+ # Dative.
490
+ addDefaultServers : (serversArray ) ->
491
+ serverModelsArray = []
492
+ for s in serversArray
493
+ s .id = @ guid ()
494
+ serverModelsArray .push (new ServerModel (s))
495
+ serversCollection = new ServersCollection (serverModelsArray)
496
+ activeServer = serversCollection .at 0
497
+ @applicationSettings .set ' servers' , serversCollection
498
+ @applicationSettings .set ' activeServer' , activeServer
499
+ @applicationSettings .save ()
500
+ @ initializeContinue ()
501
+
502
+ # Fetch servers.json. This is a JSON object that contains an array of
503
+ # server objects. This allows the default list of (OLD/FieldDB) servers
504
+ # that this Dative knows about to be specified at runtime.
505
+ fetchServers : ->
506
+ if @applicationSettings .usingDefaults
507
+ url = ' servers.json'
508
+ $ .ajax
509
+ url : url
510
+ type : ' GET'
511
+ dataType : ' json'
512
+ error : (jqXHR , textStatus , errorThrown ) ->
513
+ console .log " Ajax request for #{ url} threw an error:
514
+ #{ errorThrown} "
515
+ @ initializeContinue ()
516
+ success : (serversArray , textStatus , jqXHR ) =>
517
+ @ addDefaultServers serversArray
518
+ else
519
+ @ initializeContinue ()
520
+
482
521
# Size the #appview div relative to the window size
483
522
matchWindowDimensions : ->
484
523
@ $ (' #appview' ).css height : $ (window ).height () - 50
0 commit comments