scidea-schools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/MIT-LICENSE +7 -0
  2. data/README.md +1 -0
  3. data/Rakefile +2 -0
  4. data/app/assets/javascripts/backbone_apps/models/school.js +13 -0
  5. data/app/assets/javascripts/backbone_apps/school_selector.js +396 -0
  6. data/app/assets/stylesheets/scidea/admin/pages/schools/edit_user.css +57 -0
  7. data/app/assets/stylesheets/scidea/admin/pages/schools/user_migrate.css +3 -0
  8. data/app/assets/stylesheets/scidea/pages/schools/user_profile.css +53 -0
  9. data/app/controllers/admin/schools_controller.rb +125 -0
  10. data/app/controllers/application_controller.rb +5 -0
  11. data/app/controllers/schools_controller.rb +58 -0
  12. data/app/controllers/test/scidea_schools_qunit_tests_controller.rb +51 -0
  13. data/app/helpers/schools_helper.rb +22 -0
  14. data/app/models/school.rb +93 -0
  15. data/app/themes/global_sass/_mixins.scss +5 -0
  16. data/app/themes/scidea/sass/_config.scss +7 -0
  17. data/app/themes/scidea/sass/admin/pages/schools/edit_user.scss +14 -0
  18. data/app/themes/scidea/sass/admin/pages/schools/user_migrate.scss +21 -0
  19. data/app/themes/scidea/sass/components/_schools.scss +170 -0
  20. data/app/themes/scidea/sass/pages/schools/user_profile.scss +6 -0
  21. data/app/views/admin/schools/_form.html.erb +20 -0
  22. data/app/views/admin/schools/_school.html.erb +10 -0
  23. data/app/views/admin/schools/_search.html.erb +14 -0
  24. data/app/views/admin/schools/confirm_migration.html.erb +17 -0
  25. data/app/views/admin/schools/edit.html.erb +7 -0
  26. data/app/views/admin/schools/index.html.erb +60 -0
  27. data/app/views/admin/schools/new.html.erb +5 -0
  28. data/app/views/admin/schools/new_migration.html.erb +76 -0
  29. data/app/views/admin/schools/show.html.erb +46 -0
  30. data/app/views/admin/users/_profile_show_school.html.erb +4 -0
  31. data/app/views/admin/users/_school_edit.html.erb +5 -0
  32. data/app/views/layouts/application.html.erb +14 -0
  33. data/app/views/schools/_form.html.erb +19 -0
  34. data/app/views/schools/_profile_form.html.erb +43 -0
  35. data/app/views/schools/_script_form.html.erb +3 -0
  36. data/app/views/schools/_search.html.erb +6 -0
  37. data/app/views/users/_school_edit.html.erb +5 -0
  38. data/config/compass.rb +28 -0
  39. data/config/cucumber.yml +8 -0
  40. data/config/environment.rb +18 -0
  41. data/config/initializers/schools_assets.rb +6 -0
  42. data/config/locales/en.yml +8 -0
  43. data/config/requirejs.yml +2 -0
  44. data/config/routes.rb +25 -0
  45. data/db/seeds.rb +14 -0
  46. data/features/applying_for_seminars.feature +0 -0
  47. data/features/edit_seminar_application.feature +42 -0
  48. data/features/manage_users.feature +23 -0
  49. data/features/qunit/qunit.feature +7 -0
  50. data/features/schools/manage_schools.feature +87 -0
  51. data/features/schools/schools.feature +208 -0
  52. data/features/step_definitions/audience_steps.rb +10 -0
  53. data/features/step_definitions/authentication_steps.rb +34 -0
  54. data/features/step_definitions/custom_form_steps.rb +33 -0
  55. data/features/step_definitions/email_steps.rb +206 -0
  56. data/features/step_definitions/menu_steps.rb +4 -0
  57. data/features/step_definitions/misc_steps.rb +52 -0
  58. data/features/step_definitions/qunit_steps.rb +20 -0
  59. data/features/step_definitions/registration_steps.rb +17 -0
  60. data/features/step_definitions/school_steps.rb +35 -0
  61. data/features/step_definitions/seminar_application_steps.rb +16 -0
  62. data/features/step_definitions/seminar_steps.rb +5 -0
  63. data/features/step_definitions/steps.rb +0 -0
  64. data/features/step_definitions/user_steps.rb +16 -0
  65. data/features/step_definitions/web_steps.rb +211 -0
  66. data/features/support/env.rb +21 -0
  67. data/features/support/hooks.rb +16 -0
  68. data/features/support/paths.rb +39 -0
  69. data/features/support/seed_user_roles.rb +16 -0
  70. data/features/support/selectors.rb +66 -0
  71. data/lib/generators/scidea/schools/migrations_generator.rb +14 -0
  72. data/lib/generators/scidea/schools/removal_migrations_generator.rb +14 -0
  73. data/lib/generators/scidea/schools/templates/removal/scidea_schools_99_remove.rb +35 -0
  74. data/lib/generators/scidea/schools/templates/scidea_schools_01_install.rb +35 -0
  75. data/lib/scidea/schools/engine.rb +31 -0
  76. data/lib/scidea/schools/models/ability.rb +28 -0
  77. data/lib/scidea/schools/models/profile.rb +25 -0
  78. data/lib/scidea/schools/version.rb +5 -0
  79. data/lib/scidea/schools.rb +5 -0
  80. data/lib/scidea-schools.rb +1 -0
  81. data/lib/tasks/db/seed.rake +5 -0
  82. data/qunit/helpers/qunit.js +1598 -0
  83. data/qunit/html_fixtures/backbone_apps/_school_selector.html.erb +16 -0
  84. data/qunit/test_runner.html.erb +25 -0
  85. data/qunit/tests/backbone_apps/school_selector.js +50 -0
  86. data/spec/factories/schools.rb +10 -0
  87. data/spec/models/ability_spec.rb +27 -0
  88. data/spec/models/profile_spec.rb +38 -0
  89. data/spec/models/school_spec.rb +304 -0
  90. data/spec/routing/admin/admin_schools_routing_spec.rb +47 -0
  91. data/spec/routing/schools_routing_spec.rb +35 -0
  92. data/spec/spec_helper.rb +48 -0
  93. metadata +249 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Scitent, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Scidea Schools Extension
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'rake'
@@ -0,0 +1,13 @@
1
+ define([
2
+ 'backbone',
3
+ ],
4
+ function(Backbone){
5
+
6
+ return Backbone.Model.extend({
7
+ url : function() {
8
+ return '/schools' + (this.id ? '/' + this.id : '');
9
+ }
10
+ });
11
+
12
+ });
13
+
@@ -0,0 +1,396 @@
1
+ define([
2
+ 'jquery',
3
+ 'underscore',
4
+ 'backbone',
5
+ 'backbone_apps/models/school',
6
+ 'jquery_plugins/jquery.formparams',
7
+ 'jquery_plugins/jquery.blockUI-2.3.7'
8
+ ],
9
+ function($, _, Backbone, School){
10
+
11
+ $.blockUI.defaults.css = {};
12
+
13
+ var SchoolSelectorView = Backbone.View.extend({
14
+ newSchoolForm : $($('#new-school-form-tpl').html()).html(),
15
+
16
+ stateDefs : {
17
+ 'schools-found' : function() {
18
+ $(this.el).addClass('schools-found').removeClass('schools-not-found');
19
+ },
20
+ 'schools-not-found' : function() {
21
+ $(this.el).addClass('schools-not-found').removeClass('schools-found');
22
+ },
23
+ 'adding-school' : function() {
24
+ $(this.el).addClass('adding-school').removeClass('cancelled-school-edit');
25
+ },
26
+ 'editing-school' : function() {
27
+ $(this.el).addClass('editing-school').removeClass('cancelled-school-edit');
28
+ },
29
+ 'cancelled-school-edit' : function() {
30
+ $(this.el).addClass('cancelled-school-edit').removeClass('adding-school editing-school');
31
+ },
32
+ 'new-school-exists' : function() {
33
+ $(this.el).addClass('new-school-exists').removeClass('adding-school editing-school');
34
+ },
35
+ 'new-school-updated' : function() {
36
+ $(this.el).addClass('new-school-updated').removeClass('adding-school editing-school');
37
+ }
38
+ },
39
+
40
+ events : {
41
+ 'click a[href="#add-new-school"]' : 'addNewSchool',
42
+ 'click a[href="#edit-new-school"]' : 'editNewSchool',
43
+ 'click a[href*="cancel-edit-school"]' : 'cancelEditSchool', // the *= attribute portion of the selector is necessary for IE7
44
+ 'click a[href="#select-new-school"]' : 'selectNewSchool',
45
+ 'click #school_submit' : 'submitSchool'
46
+ },
47
+
48
+ initialize : function(opts) {
49
+ var self = this;
50
+
51
+ _.bindAll(this,
52
+ 'validateZipcode',
53
+ 'handleSchoolsFound',
54
+ 'handleSchoolsNotFound',
55
+ 'handleNewSchoolSaved',
56
+ 'handleAudienceChange',
57
+ 'addSchoolFields',
58
+ 'setState',
59
+ 'detach',
60
+ 'reattach',
61
+ 'populateSchoolsSelect');
62
+
63
+ // used later when we detach and reattach this view element to the DOM
64
+ this.$prevEl = $(this.el).prev();
65
+
66
+ // handle changes in the audience field. show the school selector if audience is educator
67
+ this.$audienceField = opts.audienceField;
68
+ if( opts.audienceField.length ) {
69
+ this.$audienceField.live('change', this.handleAudienceChange);
70
+ this.handleAudienceChange();
71
+ }
72
+
73
+ // intialize zipcode validation and Ajax posting
74
+ this.validateZipcode = _.debounce(this.validateZipcode, 500);
75
+ this.$('#school-select-zipcode').bind('keydown', function(e) {
76
+ self.supressFormSubmission(e);
77
+ self.validateZipcode();
78
+ });
79
+
80
+ // search for a zipcode if one is pre-populated in the form; run this once per page load
81
+ var $zipcodeField = this.$('#school-select-zipcode');
82
+ var zipcode = $zipcodeField.val();
83
+ if(zipcode && zipcode.search(/\d{5}/) >= 0) {
84
+ $zipcodeField.trigger('keydown');
85
+ }
86
+
87
+ this.school = new School();
88
+ },
89
+
90
+ addNewSchool : function(e) {
91
+
92
+ var $newSchoolForm;
93
+
94
+ e.preventDefault();
95
+
96
+ this.disableSelection();
97
+ this.disableZipcodeInput();
98
+
99
+ // $('#new-school-form').show();
100
+
101
+ this.showNewSchoolForm() // a jQuery ref to the form is returned
102
+ .find('#school_zipcode')
103
+ .val( $('#school-select-zipcode').val() );
104
+
105
+ this.setState('adding-school');
106
+ },
107
+
108
+ editNewSchool : function(e) {
109
+ e.preventDefault();
110
+
111
+ this.disableSelection();
112
+ this.disableZipcodeInput();
113
+
114
+ this.showEditSchoolForm();
115
+
116
+ this.setState('editing-school');
117
+ },
118
+
119
+ selectNewSchool : function(e) {
120
+ e.preventDefault();
121
+
122
+ var zipcode = this.school.get('zipcode');
123
+
124
+ this.$('#school-select-zipcode').val(zipcode);
125
+ this.getSchoolsForZipcode(zipcode, this.school.id);
126
+ },
127
+
128
+ cancelEditSchool : function(e) {
129
+ e.preventDefault();
130
+ this.hideNewSchoolForm();
131
+ if(this.schoolsFound) { this.enableSelection(); }
132
+ this.enableZipcodeInput();
133
+ this.setState('cancelled-school-edit');
134
+ },
135
+
136
+ showSchoolForm : function(action) {
137
+ return $('#new-school-form').empty()
138
+ .append(this[action + 'SchoolForm'])
139
+ .show()
140
+ .find('#school_name')
141
+ .focus()
142
+ .end();
143
+ },
144
+
145
+ showNewSchoolForm : function() {
146
+ return this.showSchoolForm('new');
147
+ },
148
+
149
+ showEditSchoolForm : function() {
150
+ return this.showSchoolForm('edit');
151
+ },
152
+
153
+ hideNewSchoolForm : function() {
154
+ $('#new-school-form').fadeOut('slow',function(){
155
+ $(this).empty();
156
+ });
157
+ },
158
+
159
+ selectedSchoolIdFromServer : function() {
160
+ return $('#school-id').data('selected-id');
161
+ },
162
+
163
+ populateSchoolsSelect : function(optionsHTML) {
164
+
165
+ var $schoolSelect = $('#school-id'),
166
+ selectedId = this.selectedSchoolIdFromServer();
167
+
168
+ $schoolSelect.html(optionsHTML);
169
+
170
+ if( !(_.isUndefined(selectedId) || selectedId === '') ) {
171
+ $schoolSelect.val(selectedId);
172
+ }
173
+
174
+ this.populateSchoolsSelect = function(optionsHTML) {
175
+ $schoolSelect.html(optionsHTML);
176
+ };
177
+ },
178
+
179
+ enableSelection : function() {
180
+ $('#school-id').removeAttr('disabled');
181
+ },
182
+
183
+ enableZipcodeInput : function() {
184
+ $('#school-select-zipcode').removeAttr('disabled');
185
+ },
186
+
187
+ disableZipcodeInput : function() {
188
+ $('#school-select-zipcode').attr('disabled', 'disabled');
189
+ },
190
+
191
+ disableSelection : function() {
192
+ $('#school-id').attr('disabled', 'disabled');
193
+ },
194
+
195
+ supressFormSubmission : function(e) {
196
+ if(e.which == 13) {
197
+ e.stopPropagation();
198
+ e.preventDefault();
199
+ }
200
+ },
201
+
202
+ validateZipcode : function(e) {
203
+ var $zipcode = $("#school-select-zipcode");
204
+ var isValid = $zipcode.prop('validity').valid;
205
+
206
+ if(isValid) {
207
+ this.getSchoolsForZipcode($('#school-select-zipcode').val(), this.school.id || this.selectedSchoolIdFromServer());
208
+ } else {
209
+ this.disableSelection();
210
+ }
211
+ },
212
+
213
+ handleSchoolsFound : function(schoolsOptionsHTML) {
214
+ this.schoolsFound = true;
215
+ this.enableSelection();
216
+ this.enableZipcodeInput();
217
+ this.populateSchoolsSelect(schoolsOptionsHTML);
218
+ this.setState('schools-found');
219
+ },
220
+
221
+ handleSchoolsNotFound : function() {
222
+ this.schoolsFound = false;
223
+ this.enableZipcodeInput();
224
+ this.populateSchoolsSelect('<option>No educational institutions found</option>');
225
+ this.setState('schools-not-found');
226
+ },
227
+
228
+ handleNewSchoolSaved : function(saveOp) {
229
+
230
+ var context = this,
231
+ schoolsOptionsCache = this.getSchoolsForZipcode,
232
+ zipcode = this.school.get('zipcode'),
233
+ id = this.school.id;
234
+
235
+ /* update the DOM after we've fetched the new edit form so the old edit
236
+ form isn't accidentally used if the user *quickly* clicks the edit link
237
+ */
238
+ this.fetchEditSchoolForm( function() {
239
+ if(saveOp == 'update') {
240
+ delete schoolsOptionsCache[zipcode + id];
241
+ context.setState('new-school-updated');
242
+ } else {
243
+ context.setState('new-school-exists');
244
+ }
245
+
246
+ $('#school-id-input .inline-errors').remove();
247
+
248
+ context.$('#school-select-zipcode').val(zipcode).trigger('refreshCustomValidityRules');
249
+ context.getSchoolsForZipcode(zipcode, id);
250
+
251
+ $('#new-school-form').unblock({fadeOut: 0});
252
+ context.hideNewSchoolForm();
253
+ } );
254
+ },
255
+
256
+ handleNewSchoolSavedError : function(model, response) {
257
+ var errors = $.parseJSON(response.responseText);
258
+ this.editSchoolForm = errors.html;
259
+ this.showEditSchoolForm();
260
+ },
261
+
262
+ handleAudienceChange : function() {
263
+ var selectedText = this.$audienceField.find(':selected').text();
264
+ if( selectedText.toLowerCase() != 'educator' ) {
265
+ this.detach();
266
+ } else {
267
+ this.addSchoolFields();
268
+ }
269
+ },
270
+
271
+ addSchoolFields : function() {
272
+ // if not already in DOM, add it
273
+ if(!$($(this.el).selector).length) {
274
+ this.reattach();
275
+ }
276
+ },
277
+
278
+ fetchEditSchoolForm : function(success_callback) {
279
+ $.ajax({
280
+ url : '/schools/' + this.school.id + '/edit',
281
+ context: this,
282
+ success : function(response, textStatus, jqXHR) {
283
+ if(success_callback) { success_callback(); }
284
+
285
+ this.editSchoolForm = response;
286
+ }
287
+ });
288
+ },
289
+
290
+ setState : function(state) {
291
+ this.stateDefs[state].call(this);
292
+ },
293
+
294
+ getSchoolsForZipCodeXhr : function(zipcode, selectedId) {
295
+
296
+ this.enableSelection();
297
+ $('#school-id option').first().text('Searching...');
298
+
299
+ $.ajax('/schools', {
300
+ context : this,
301
+ data : {
302
+ zipcode : zipcode,
303
+ new_school_id : selectedId
304
+ },
305
+ success : function(response, textStatus, jqXHR) {
306
+
307
+ if(response.html) {
308
+ this.handleSchoolsFound(response.html);
309
+ } else {
310
+ this.handleSchoolsNotFound();
311
+ }
312
+
313
+ // memoize the response html on the getSchoolsForZipCode function
314
+ this.getSchoolsForZipcode[zipcode + (this.school.id || '')] = response.html;
315
+ }
316
+ });
317
+
318
+ },
319
+
320
+ getSchoolsForZipcode : function(zipcode, selectedId) {
321
+
322
+ this.disableZipcodeInput();
323
+
324
+ var schoolOptionsHTML = arguments.callee[zipcode + ( selectedId || '' )];
325
+
326
+ if(_.isUndefined(schoolOptionsHTML)) {
327
+
328
+ this.getSchoolsForZipCodeXhr(zipcode, selectedId);
329
+
330
+ } else {
331
+
332
+ if(schoolOptionsHTML === '') {
333
+ this.handleSchoolsNotFound();
334
+ } else {
335
+ this.handleSchoolsFound(schoolOptionsHTML);
336
+ }
337
+
338
+ }
339
+ return schoolOptionsHTML;
340
+ },
341
+
342
+ clearSchoolQueryCacheFor : function(zipcode, id) {
343
+ var schoolsQueryCache = this.getSchoolsForZipcode;
344
+ delete schoolsQueryCache[zipcode + id];
345
+ },
346
+
347
+ submitSchool : function(e) {
348
+ e.preventDefault();
349
+ var formParamsConvertTypes = false,
350
+ formParams = this.$('#new-school-form').formParams(formParamsConvertTypes),
351
+ saveOp = this.school.id ? 'update' : 'create';
352
+
353
+ $('#new-school-form').block({
354
+ message: '<span class="text">Saving educational institution</span> <span class="icon-loading"></span>',
355
+ overlayCSS: {
356
+ backgroundColor: null,
357
+ opacity: null
358
+ }
359
+ });
360
+
361
+ // Clear the cached search result related to the new school, as the user is now changing the zipcode
362
+ if(saveOp == 'update' && formParams.school.zipcode != this.school.get('zipcode')) {
363
+ this.clearSchoolQueryCacheFor(this.school.get('zipcode'), this.school.id);
364
+ }
365
+
366
+ this.school.save(formParams, {
367
+ success : _.bind(this.handleNewSchoolSaved, this, saveOp),
368
+ error : _.bind(this.handleNewSchoolSavedError, this)
369
+ });
370
+ },
371
+
372
+ detach : function() {
373
+ $(this.el).detach();
374
+ },
375
+
376
+ reattach : function() {
377
+ $(this.el).insertAfter(this.$prevEl);
378
+ }
379
+
380
+ });
381
+
382
+ // called when plugin is loaded and document is ready
383
+ return function($) {
384
+ var $schoolSelectorEl = $('#profile-school');
385
+
386
+ if($schoolSelectorEl.length) {
387
+ new SchoolSelectorView({
388
+ el : $schoolSelectorEl.get(),
389
+ audienceField : $('#user_profile_attributes_audience_id')
390
+ });
391
+ }
392
+
393
+ return SchoolSelectorView;
394
+ }; // anonymous define return function
395
+
396
+ }); // define
@@ -0,0 +1,57 @@
1
+ #school-selection-fields { margin-bottom: .357em; }
2
+ #school-selection-fields legend { display: block; width: 25%; float: left; padding: .35em 5px 0 0; font-size: 1em; }
3
+ #school-selection-fields label { position: absolute !important; clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ clip: rect(1px, 1px, 1px, 1px); }
4
+ #school-selection-fields li { margin-bottom: .25em !important; }
5
+ #school-selection-fields p.inline-hints { clear: both; padding-left: 0 !important; }
6
+ .schools-found #school-selection-fields p.inline-hints { display: none; }
7
+
8
+ #school-select-zipcode { width: 45px !important; min-width: 0 !important; margin-right: 5px; }
9
+
10
+ #school-select-zipcode-input, #school-id-input { float: left; width: auto; }
11
+
12
+ #main form #school-id-input p.inline-errors { padding: 0; margin: 3px 0 0; }
13
+
14
+ #school-id { width: 200px; }
15
+
16
+ #new-school { float: left; width: 72%; margin: 0; padding: 0 0 0 25%; }
17
+ #new-school .inline-hints { padding-left: 0 !important; margin: 0 !important; }
18
+
19
+ #new-school-form { display: none; background: #EFF4FF; border: 1px solid #A5B9C8; -moz-border-radius: 4px; -webkit-border-radius: 4px; -o-border-radius: 4px; -ms-border-radius: 4px; -khtml-border-radius: 4px; border-radius: 4px; padding: 1.07em 15px; width: 375px; }
20
+ .ie7 #new-school-form { width: 400px; }
21
+ #main form #new-school-form p.inline-errors { margin: 3px 0 0 100px; }
22
+ #new-school-form .blockOverlay { background: #EFF4FF; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50); opacity: 0.5; -moz-border-radius: 3px; -webkit-border-radius: 3px; -o-border-radius: 3px; -ms-border-radius: 3px; -khtml-border-radius: 3px; border-radius: 3px; }
23
+ #new-school-form .blockMsg { border: 1px solid #aaa; -moz-box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; -webkit-box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; -o-box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; -moz-border-radius: 4px; -webkit-border-radius: 4px; -o-border-radius: 4px; -ms-border-radius: 4px; -khtml-border-radius: 4px; border-radius: 4px; padding: 5px 10px 3px; color: #444; background: #fff; line-height: 1em; }
24
+ .ie7 #new-school-form .blockMsg .text { position: relative; top: -3px; }
25
+ #new-school-form .blockMsg .icon-loading { background: url('/images/scidea/icons/loading_barber_shop_pole.gif') 50% 40% no-repeat; width: 220px; display: -moz-inline-box; -moz-box-orient: vertical; display: inline-block; vertical-align: middle; *vertical-align: auto; height: 0px; padding: 20px 0 0; margin-left: 5px; }
26
+ #new-school-form .blockMsg .icon-loading { *display: inline; }
27
+ .adding-school #new-school-form, .editing-school #new-school-form { display: block; }
28
+ #new-school-form ol { padding: 0 !important; margin-bottom: 0 !important; }
29
+ #new-school-form li { margin-bottom: .714em; }
30
+ #new-school-form input[type="text"] { background: #fff !important; border-color: #ccc; }
31
+ #new-school-form label { width: 100px; }
32
+ #new-school-form .buttons { padding-left: 105px !important; margin-bottom: 0 !important; }
33
+
34
+ #school_submit { margin-right: 10px; }
35
+
36
+ .schools-found #add-school { display: block; }
37
+ #add-school, .adding-school #add-school, .new-school-exists #add-school { display: none; }
38
+
39
+ .new-school-exists #edit-school { display: block; }
40
+ #edit-school, .editing-school #edit-school, .schools-not-found #edit-school { display: none; }
41
+
42
+ .schools-not-found #schools-not-found-message { display: block; }
43
+ #schools-not-found-message, .adding-school #schools-not-found-message { display: none; }
44
+
45
+ .new-school-exists a[href="#add-new-school"] { display: none; }
46
+
47
+ a[href="#select-new-school"] { display: none; }
48
+ .new-school-exists a[href="#select-new-school"] { display: inline; }
49
+
50
+ #schools-initial-message { display: block; }
51
+ .schools-not-found #schools-initial-message { display: none; }
52
+
53
+ a[href="#add-new-school"] { display: none; }
54
+
55
+ a[href="#select-new-school"] { display: none; }
56
+
57
+ span #edit-school { display: none; }
@@ -0,0 +1,3 @@
1
+ #main #school-migration-message { border-color: #D8CF7B; background-color: #FCFCC7; padding: .75em 1em; -moz-border-radius: 8px; -webkit-border-radius: 8px; -o-border-radius: 8px; -ms-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; color: #333; -moz-box-shadow: #bfbfbf 0px 2px 3px; -webkit-box-shadow: #bfbfbf 0px 2px 3px; -o-box-shadow: #bfbfbf 0px 2px 3px; box-shadow: #bfbfbf 0px 2px 3px; margin-bottom: 1.5em; font-size: 120%; }
2
+ #main #school-migration-message p { margin-bottom: .5em; }
3
+ #main #school-migration-message address { padding: 0 0 0 4em; }
@@ -0,0 +1,53 @@
1
+ #school-selection-fields { margin-bottom: .357em; }
2
+ #school-selection-fields legend { display: block; width: 25%; float: left; padding: .35em 5px 0 0; font-size: 1em; }
3
+ #school-selection-fields label { position: absolute !important; clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ clip: rect(1px, 1px, 1px, 1px); }
4
+ #school-selection-fields li { margin-bottom: .25em !important; }
5
+ #school-selection-fields p.inline-hints { clear: both; padding-left: 0 !important; }
6
+ .schools-found #school-selection-fields p.inline-hints { display: none; }
7
+
8
+ #school-select-zipcode { width: 45px !important; min-width: 0 !important; margin-right: 5px; }
9
+
10
+ #school-select-zipcode-input, #school-id-input { float: left; width: auto; }
11
+
12
+ #main form #school-id-input p.inline-errors { padding: 0; margin: 3px 0 0; }
13
+
14
+ #school-id { width: 200px; }
15
+
16
+ #new-school { float: left; width: 72%; margin: 0; padding: 0 0 0 25%; }
17
+ #new-school .inline-hints { padding-left: 0 !important; margin: 0 !important; }
18
+
19
+ #new-school-form { display: none; background: #EFF4FF; border: 1px solid #A5B9C8; -moz-border-radius: 4px; -webkit-border-radius: 4px; -o-border-radius: 4px; -ms-border-radius: 4px; -khtml-border-radius: 4px; border-radius: 4px; padding: 1.07em 15px; width: 375px; }
20
+ .ie7 #new-school-form { width: 400px; }
21
+ #main form #new-school-form p.inline-errors { margin: 3px 0 0 100px; }
22
+ #new-school-form .blockOverlay { background: #EFF4FF; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50); opacity: 0.5; -moz-border-radius: 3px; -webkit-border-radius: 3px; -o-border-radius: 3px; -ms-border-radius: 3px; -khtml-border-radius: 3px; border-radius: 3px; }
23
+ #new-school-form .blockMsg { border: 1px solid #aaa; -moz-box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; -webkit-box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; -o-box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px; -moz-border-radius: 4px; -webkit-border-radius: 4px; -o-border-radius: 4px; -ms-border-radius: 4px; -khtml-border-radius: 4px; border-radius: 4px; padding: 5px 10px 3px; color: #444; background: #fff; line-height: 1em; }
24
+ .ie7 #new-school-form .blockMsg .text { position: relative; top: -3px; }
25
+ #new-school-form .blockMsg .icon-loading { background: url('/images/scidea/icons/loading_barber_shop_pole.gif') 50% 40% no-repeat; width: 220px; display: -moz-inline-box; -moz-box-orient: vertical; display: inline-block; vertical-align: middle; *vertical-align: auto; height: 0px; padding: 20px 0 0; margin-left: 5px; }
26
+ #new-school-form .blockMsg .icon-loading { *display: inline; }
27
+ .adding-school #new-school-form, .editing-school #new-school-form { display: block; }
28
+ #new-school-form ol { padding: 0 !important; margin-bottom: 0 !important; }
29
+ #new-school-form li { margin-bottom: .714em; }
30
+ #new-school-form input[type="text"] { background: #fff !important; border-color: #ccc; }
31
+ #new-school-form label { width: 100px; }
32
+ #new-school-form .buttons { padding-left: 105px !important; margin-bottom: 0 !important; }
33
+
34
+ #school_submit { margin-right: 10px; }
35
+
36
+ .schools-found #add-school { display: block; }
37
+ #add-school, .adding-school #add-school, .new-school-exists #add-school { display: none; }
38
+
39
+ .new-school-exists #edit-school { display: block; }
40
+ #edit-school, .editing-school #edit-school, .schools-not-found #edit-school { display: none; }
41
+
42
+ .schools-not-found #schools-not-found-message { display: block; }
43
+ #schools-not-found-message, .adding-school #schools-not-found-message { display: none; }
44
+
45
+ .new-school-exists a[href="#add-new-school"] { display: none; }
46
+
47
+ a[href="#select-new-school"] { display: none; }
48
+ .new-school-exists a[href="#select-new-school"] { display: inline; }
49
+
50
+ #schools-initial-message { display: block; }
51
+ .schools-not-found #schools-initial-message { display: none; }
52
+
53
+ #admin-new-school { display: none; }
@@ -0,0 +1,125 @@
1
+ module Admin
2
+ class SchoolsController < ApplicationController
3
+
4
+ ssl_exceptions
5
+
6
+ before_filter :authenticate_user!
7
+ authorize_resource
8
+
9
+ include ::ActionView::Helpers::TextHelper
10
+
11
+ has_widgets do |root|
12
+ root << widget(:paginated_list) << widget(:datatable)
13
+ end
14
+
15
+ # GET /schools
16
+ def index
17
+ @schools = School.search(params[:search]).
18
+ order(sort_column + ' ' + sort_direction).
19
+ paginate(:per_page => per_page, :page => params[:page])
20
+ end
21
+
22
+ # GET /schools/1
23
+ def show
24
+ @school = School.where("id = ?", params[:id]).first
25
+ end
26
+
27
+ # GET /schools/new
28
+ def new
29
+ @school = School.new :approved => true
30
+ end
31
+
32
+ # GET /schools/1/edit
33
+ def edit
34
+ @school = School.where("id = ?", params[:id]).first
35
+ end
36
+
37
+ # POST /schools
38
+ def create
39
+ @school = School.new(params[:school])
40
+
41
+ check_school_approved(@school, params)
42
+
43
+ if @school.save
44
+ redirect_to(admin_school_path(@school), :flash => { :success => "Educational institution was successfully created." })
45
+ else
46
+ render :action => "new"
47
+ end
48
+ end
49
+
50
+ # PUT /schools/1
51
+ def update
52
+ @school = School.where("id = ?", params[:id]).first
53
+
54
+ check_school_approved(@school, params)
55
+
56
+ if @school.update_attributes(params[:school])
57
+ redirect_to(admin_school_path(@school), :flash => { :success => "Educational institution was successfully updated." })
58
+ else
59
+ render :action => "edit"
60
+ end
61
+ end
62
+
63
+ # DELETE /schools/1
64
+ def destroy
65
+ @school = School.where("id = ?", params[:id]).first
66
+ @school.destroy
67
+
68
+ redirect_to(admin_schools_path, :flash => { :success => "Educational institution was successfully deleted." })
69
+ end
70
+
71
+ # GET /schools/1/migration/new
72
+ def new_migration
73
+ @school = School.where("id = ?", params[:id]).first
74
+
75
+ @target_schools = School.search(params[:search]).
76
+ without_school(@school).
77
+ order(sort_column + ' ' + sort_direction).
78
+ paginate(:per_page => per_page, :page => params[:page])
79
+ end
80
+
81
+ # GET /schools/1/migration/2/confirm
82
+ def confirm_migration
83
+ @school = School.where("id = ?", params[:id]).first
84
+ @target_school = School.where("id = ?", params[:target_school_id]).first
85
+ end
86
+
87
+ # POST /schools/1/migration/2
88
+ def create_migration
89
+ @school = School.where("id = ?", params[:id]).first
90
+ @target_school = School.where("id = ?", params[:target_school_id]).first
91
+
92
+ migrated_users = @school.migrate_users_to(@target_school) if @school && @target_school
93
+
94
+ if @school && @target_school && migrated_users.size >= 0
95
+ redirect_to(admin_schools_path, :flash => { :success => "Successfully migrated #{pluralize(migrated_users.size, 'user')} " +
96
+ "from #{@school.name} to #{@target_school.name}." })
97
+ else
98
+ flash[:error] = "Unable to migrate users between educational institution"
99
+ @target_schools = School.search(params[:search]).
100
+ without_school(@school).
101
+ order(sort_column + ' ' + sort_direction).
102
+ paginate(:per_page => per_page, :page => params[:page])
103
+ render :new_migration
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def check_school_approved(school, params)
110
+ if params[:school] && params[:school][:approved]
111
+ school.approved = params[:school][:approved] == '1'
112
+ end
113
+ end
114
+
115
+
116
+ def per_page
117
+ %w[25 50 100].include?(params[:per_page]) ? params[:per_page] : "25"
118
+ end
119
+
120
+ def sort_column
121
+ %w[name city state zipcode approved].include?(params[:sort]) ? params[:sort] : "name"
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ include ::SslRequirement
3
+
4
+ protect_from_forgery
5
+ end