jquery_validation 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWRmNmZiNzg4ZGEzNWY4ZDk1ZjhmZDk3OTlkZGI1Mjc0MjUyN2NjMA==
5
+ data.tar.gz: !binary |-
6
+ MTA0NGJlZTNlM2ZkYTQ2YmI5NDczMzUyYmEzMzFhODZmNTRjMTg2OQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MmFlNDdmZDIyZmUwMWE4YTU5M2I2ZjYyNGNlYjQ2ODc3OGMzOTMyZjcxZjE2
10
+ OTQ0MjQ4NTRiYmY0MTllMmNmNzAwNTA4MWU4ZDFiM2E0ZDk0NTdhMDFkMDMw
11
+ MDM1MzYwM2NjOTQ5Y2ZiYWYyYzE3ZDdmMTE0Yjc4MzM0OTNlOTM=
12
+ data.tar.gz: !binary |-
13
+ Nzg2MTJkMDFiNTQ0ODcyODhjN2ExNjUwYzZjZWJiNTYyZWNmYjczNmVlNzQ0
14
+ ZTkxODg2MjM4NzFhZmIzMGU1MzAyYjUxN2E1YjQzMWQ4NzQ0YThjMzFmNWE0
15
+ YjUxMzNmN2QyMDU0M2U4MzVkYzcyNTA4OWY5MmQ1MzAzZjRkMDQ=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery_validation.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 shanky-munjal
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # JqueryValidation
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jquery_validation'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jquery_validation
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery_validation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery_validation"
8
+ spec.version = JqueryValidation::VERSION
9
+ spec.authors = ["shanky-munjal"]
10
+ spec.email = ["shanky.munjal@quovantis.com"]
11
+ spec.description = %q{It will handle validations inline}
12
+ spec.summary = %q{Validations with ajax}
13
+ spec.homepage = "http://rubygems.org/gems/jquery_validation"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ class JqueryValidationGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("../templates", __FILE__)
3
+ desc "This generator installs jquery validation to Asset Pipeline"
4
+
5
+ def add_assets
6
+ copy_file "inline_validate.js", "app/assets/javascripts/inline_validate.js"
7
+ copy_file "validation_controller.rb", "app/controllers/validation_controller.rb"
8
+ end
9
+ end
@@ -0,0 +1,57 @@
1
+ $(document).on("blur", ".check_validation", function(event){
2
+ field_name = $(this).attr('name')
3
+ attr_name = field_name.match(/\[(.*?)\]/)[1]
4
+ model = field_name.split('[')[0]
5
+ value = $(this).val()
6
+ _this = $(this)
7
+ $.ajax({
8
+ url: "/validate_field", //sumbits it to the given url of the form
9
+ data: {field_name: field_name, model: model, value: value}
10
+ }).success(function(data){
11
+ _span = _this.parent().find("span.error_message")
12
+ if (data.valid != true){
13
+ _msg = humanize(field_name) + ' ' + data.valid[0]
14
+ _error = "<div class = 'error'>" + _msg + "</div>"
15
+ _span.html(_error)
16
+ }else{
17
+ _span.html('')
18
+ }
19
+ });
20
+ });
21
+
22
+ $(document).on("click", ".submit-modal", function(event){
23
+ model = $(this).data('model');
24
+ form = $('.validate-form')
25
+ valuesToSubmit = form.serialize();
26
+ valuesToSubmit += "&model="+model
27
+ if (form.attr('id').match('edit_')){
28
+ id = form.attr('action').split('/')[2]
29
+ valuesToSubmit += "&existing_record=" + true + "&id=" + id
30
+ }
31
+ $.ajax({
32
+ url: "/validate_model", //sumbits it to the given url of the form
33
+ data: valuesToSubmit,
34
+ }).success(function(data){
35
+ if (data.valid != true){
36
+ $.each(data.keys, function( index, value ) {
37
+ field_id = '#' + model + '_' + value
38
+ _msg = humanize(value) + ' ' + data.obj[value]
39
+ _error = "<div class = 'error'>" + _msg + "</div>"
40
+ $(field_id).parent().find("span.error_message").html(_error)
41
+ });
42
+ }else{
43
+ $('form.validate-form').submit();
44
+ }
45
+ });
46
+ });
47
+
48
+
49
+ ucwords = function(str) {
50
+ return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
51
+ return $1.toUpperCase();
52
+ });
53
+ }
54
+
55
+ humanize = function(str){
56
+ return ucwords(str).replace(/_/g, ' ')
57
+ }
@@ -0,0 +1,25 @@
1
+ class ValidationController < ApplicationController
2
+
3
+ def validate_field
4
+ _valid = params[:model].classify.constantize.valid_attribute?(params[:field_name], params[:value])
5
+ render :json => { :valid => _valid}
6
+ end
7
+
8
+ def validate_model
9
+ if params[:existing_record]
10
+ @entity = params[:model].classify.constantize.find(params[:id])
11
+ @entity.update_attributes(params[params[:model].to_sym])
12
+ else
13
+ @entity = params[:model].classify.constantize.new(params[params[:model].to_sym])
14
+ end
15
+ if @entity.valid?
16
+ _valid = true
17
+ else
18
+ _valid = false
19
+ _keys = @entity.errors.keys
20
+ _obj = @entity.errors
21
+ end
22
+ render :json => { valid: _valid, keys: _keys, obj: _obj}
23
+ end
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ require "jquery_validation/version"
2
+ require 'jquery_validation/railtie' if defined? Rails
3
+
4
+ module JqueryValidation
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,10 @@
1
+ require "jquery_validation/validate_model"
2
+ module JqueryValidation
3
+ class Railtie < Rails::Railtie
4
+ initializer "jquery_validation.validate_model" do |app|
5
+ ActiveSupport.on_load :active_record do
6
+ extend ValidateModel
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module JqueryValidation
2
+ module ValidateModel
3
+ def valid_attribute?(_attr, value)
4
+ mock = self.new(_attr => value)
5
+ if mock.valid?
6
+ true
7
+ else
8
+ if mock.errors.has_key?(_attr.to_sym)
9
+ mock.errors[_attr.to_sym]
10
+ else
11
+ true
12
+ end
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryValidation
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - shanky-munjal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: It will handle validations inline
42
+ email:
43
+ - shanky.munjal@quovantis.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - jquery_validation.gemspec
54
+ - lib/generators/jquery_validation/USAGE
55
+ - lib/generators/jquery_validation/jquery_validation_generator.rb
56
+ - lib/generators/jquery_validation/templates/inline_validate.js
57
+ - lib/generators/jquery_validation/templates/validation_controller.rb
58
+ - lib/jquery_validation.rb
59
+ - lib/jquery_validation/railtie.rb
60
+ - lib/jquery_validation/validate_model.rb
61
+ - lib/jquery_validation/version.rb
62
+ homepage: http://rubygems.org/gems/jquery_validation
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.1.4
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Validations with ajax
86
+ test_files: []