Serialize radio button values and add styles

fixes #CNVS-6405

Change-Id: Ia8fa25d00997b333a6fce0082877ef038948136f
Reviewed-on: https://gerrit.instructure.com/21709
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
Product-Review: Bracken Mosbacker <bracken@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Strong <clare@instructure.com>
This commit is contained in:
Sterling Cobb 2013-06-25 10:00:49 -06:00
parent 8a52963a25
commit 2bbe9eff30
8 changed files with 64 additions and 48 deletions

View File

@ -2,43 +2,44 @@ define [
'jquery'
'underscore'
], ($, _) ->
rselectTextarea = /^(?:select|textarea)/i
rcheckboxOrRadio = /checkbox|radio/i
rCRLF = /\r?\n/g
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week|checkbox|radio|file)$/i
isInput = (el) ->
el.name && !el.disabled && rselectTextarea.test(el.nodeName) or rinput.test(el.type)
getValue = (el) ->
resultFor = (val) ->
name: el.name
el: el
value: if _.isString(val) then val.replace( rCRLF, "\r\n" ) else val
$input = $(el)
val = if rcheckboxOrRadio.test(el.type)
el.checked
else if el.type == 'file'
el if $input.val()
else if $input.hasClass 'datetime_field_enabled'
# datepicker doesn't clear the data date attribute when a date is deleted
if $input.val() == ""
null
else
$input.data('date') || null
else if $input.data('rich_text')
$input.editorBox('get_code', false)
else
$input.val()
if _.isArray val
_.map val, resultFor
else
resultFor val
$.fn.serializeForm = ->
rselectTextarea = /^(?:select|textarea)/i
rcheckboxOrRadio = /checkbox|radio/i
rCRLF = /\r?\n/g
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week|checkbox|radio|file)$/i
rcheckboxOrRadio = /checkbox/i if this.is('[serialize-radio-value]')
isInput = (el) ->
el.name && !el.disabled && rselectTextarea.test(el.nodeName) or rinput.test(el.type)
getValue = (el) ->
resultFor = (val) ->
name: el.name
el: el
value: if _.isString(val) then val.replace( rCRLF, "\r\n" ) else val
$input = $(el)
val = if rcheckboxOrRadio.test(el.type)
el.checked
else if el.type == 'file'
el if $input.val()
else if $input.hasClass 'datetime_field_enabled'
# datepicker doesn't clear the data date attribute when a date is deleted
if $input.val() == ""
null
else
$input.data('date') || null
else if $input.data('rich_text')
$input.editorBox('get_code', false)
else
$input.val()
if _.isArray val
_.map val, resultFor
else
resultFor val
_.chain(this[0].elements || this.find(':input'))
.filter(isInput)
.map(getValue)

View File

@ -13,6 +13,10 @@ define [
@optionProperty 'selectOptions'
template: template
initialize: ->
super
$.subscribe 'resetForm', @resetForm
els:
'#converter' : '$converter'
@ -76,7 +80,7 @@ define [
#
# @api private
resetForm: ->
resetForm: =>
@$formActions.hide()
@$converter.empty()
@$chooseMigrationConverter.val('none')

View File

@ -437,6 +437,7 @@ class AssessmentQuestion < ActiveRecord::Base
# we want to put it in a bank named after the assessment it's in
bank_map = {}
assessments = data['assessments'] ? data['assessments']['assessments'] : []
assessments ||= []
assessments.each do |assmnt|
next unless assmnt['questions']
assmnt['questions'].each do |q|

View File

@ -947,6 +947,7 @@ class Quiz < ActiveRecord::Base
def self.process_migration(data, migration, question_data)
assessments = data['assessments'] ? data['assessments']['assessments'] : []
assessments ||= []
assessments.each do |assessment|
migration_id = assessment['migration_id'] || assessment['assessment_id']
if migration.import_object?("quizzes", migration_id)

View File

@ -1,3 +1,10 @@
[type=radio].styled-radio
margin: 4px 7px 2px 2px
float: left
.muted-margin
margin-left: 20px
.top-margin
margin-top: 5px
@ -41,3 +48,6 @@ hr
.plain
color: black
.control-height
height: 30px

View File

@ -7,5 +7,5 @@
jammit_css :content_migrations
%>
<form id="migrationConverterContainer" class="form-horizontal"></form>
<form id="migrationConverterContainer" class="form-horizontal" serialize-radio-value></form>
<div id="progress" class="span10"></div>

View File

@ -15,8 +15,8 @@
<div id="converter"></div>
<div class="form-container" style="display: none">
<div class="controls">
<button class="cancelBtn btn btn-small span1">{{#t "cancel_migration"}}Cancel{{/t}}</button>&nbsp;&nbsp;<input id="submitMigration" type="submit" value="{{#t "import_migration"}}Import{{/t}}" class="btn btn-small btn-primary span2" />
<div class="controls control-height">
<input class="cancelBtn btn btn-small" type="button" value="{{#t 'cancel_migration'}}Cancel{{/t}}">&nbsp;&nbsp;<input id="submitMigration" type="submit" value="{{#t "import_migration"}}Import{{/t}}" class="btn btn-small btn-primary span2" />
</div>
</div>

View File

@ -53,14 +53,13 @@ class Canvas::Migration::Worker::CCWorker < Struct.new(:migration_id)
cm.update_conversion_progress(100)
if cm.import_immediately?
cm.import_content_without_send_later
cm.update_import_progress(100)
saved = cm.save
if converter.respond_to?(:post_process)
converter.post_process
end
end
cm.import_content_without_send_later
cm.update_import_progress(100)
saved = cm.save
if converter.respond_to?(:post_process)
converter.post_process
end
end
saved
rescue Canvas::Migration::Error
cm.add_error($!.message, :exception => $!)