mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-24 03:35:59 +08:00
fix bugs
This commit is contained in:
44
core/static/script/base/checkAndRequest.coffee
Normal file
44
core/static/script/base/checkAndRequest.coffee
Normal file
@@ -0,0 +1,44 @@
|
||||
$ ->
|
||||
$.fn.checkAndRequest = (url, callback, opts) ->
|
||||
defaults = {}
|
||||
|
||||
opts = $.extend defaults, opts
|
||||
|
||||
form = $(@)
|
||||
error = false
|
||||
data = {}
|
||||
$('#page-alert').show().find('button').nextAll().remove()
|
||||
|
||||
for k, v of opts
|
||||
item = form.find "##{k}"
|
||||
formGroup = item.closest '.form-group'
|
||||
method = v['check']
|
||||
result = switch typeof method
|
||||
when "object" then method.test item.val()
|
||||
when "function" then method()
|
||||
when "string"
|
||||
rt = switch method
|
||||
when 'required'
|
||||
item.val() isnt ''
|
||||
when ''
|
||||
true
|
||||
else
|
||||
false
|
||||
else
|
||||
false
|
||||
if result
|
||||
formGroup.addClass 'has-success'
|
||||
data[k] = item.val()
|
||||
else
|
||||
formGroup.addClass 'has-error'
|
||||
$('#page-alert').append "<p>#{v['error']}</p>"
|
||||
error = true
|
||||
|
||||
if not error
|
||||
$('#page-alert').hide()
|
||||
|
||||
$.ajax
|
||||
url: url
|
||||
method: 'post'
|
||||
data: data
|
||||
success: callback
|
||||
Reference in New Issue
Block a user