faalis_contacts 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/faalis_contacts/modules/contact.js +12 -1
- data/app/assets/javascripts/faalis_contacts/modules/contact_field.js +9 -1
- data/app/controllers/api/v1/contact_details_controller.rb +18 -0
- data/app/controllers/api/v1/contact_fields_controller.rb +3 -3
- data/app/controllers/api/v1/contacts_controller.rb +74 -36
- data/app/models/contact.rb +1 -0
- data/app/models/contact_details.rb +29 -0
- data/app/models/contact_field.rb +2 -0
- data/app/views/angularjs_templates/contact_field/details.html +8 -0
- data/app/views/angularjs_templates/contact_field/new.html +24 -0
- data/app/views/api/v1/contact_details/destroy.json.jbuilder +1 -0
- data/app/views/api/v1/contact_fields/create.json.jbuilder +1 -1
- data/app/views/api/v1/contact_fields/index.json.jbuilder +1 -1
- data/app/views/api/v1/contact_fields/show.json.jbuilder +3 -1
- data/app/views/api/v1/contact_fields/update.json.jbuilder +1 -1
- data/app/views/api/v1/contacts/index.json.jbuilder +1 -1
- data/app/views/api/v1/contacts/show.json.jbuilder +1 -1
- data/config/routes.rb +1 -0
- data/db/migrate/20140111082843_create_contact_details.rb +1 -1
- data/db/migrate/20140113071029_create_contact_fields.rb +2 -1
- data/lib/faalis_contacts/version.rb +1 -1
- data/lib/tasks/build.rake +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a36c809d5f0f7f6843cedfc245ba4a88efe4f36
|
4
|
+
data.tar.gz: 0f1b83bc292c7e01bf220f552c2bbfc46566e72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 342f28942b576db72489e94abf45e895d1de1896232bd142f36cbf088606fe03595d6659c164110f5bf5acecd0e46563f8bfebdb5a576e7fdc38f10fcfec6775
|
7
|
+
data.tar.gz: df1b97486077e0bd7d0a5b2f5939bf28a3a36d55084ca35d4511907ed7405a9240d2a20b0b1ce795d82f93376eb0ddfd8f0a1e4225e7d4262296c76a0c07aa76
|
@@ -288,7 +288,15 @@ Contacts.controller("AddContactController", ["Restangular", "$scope", "$location
|
|
288
288
|
|
289
289
|
$scope.remove_row = function(){
|
290
290
|
$scope.details_count.pop();
|
291
|
-
$scope.details.pop();
|
291
|
+
var lastobj = $scope.details.pop();
|
292
|
+
if ("id" in lastobj) {
|
293
|
+
API.all("contact_details").customDELETE(lastobj.id)
|
294
|
+
.then(function(data) {
|
295
|
+
success_message(data.msg);
|
296
|
+
}, function(data){
|
297
|
+
catch_error(data);
|
298
|
+
});
|
299
|
+
}
|
292
300
|
};
|
293
301
|
|
294
302
|
$scope.have = function(field, obj_id) {
|
@@ -307,6 +315,9 @@ Contacts.controller("AddContactController", ["Restangular", "$scope", "$location
|
|
307
315
|
};
|
308
316
|
|
309
317
|
$scope.save = function(save_another){
|
318
|
+
$("small.error").html("");
|
319
|
+
$("small.error").removeClass("error");
|
320
|
+
|
310
321
|
var contact = {contact: {
|
311
322
|
prefix: $scope.prefix,
|
312
323
|
first_name: $scope.first_name,
|
@@ -105,7 +105,11 @@ ContactFields.controller("AddContactFieldController", ["Restangular", "$scope",
|
|
105
105
|
var is_copy = false;
|
106
106
|
|
107
107
|
|
108
|
-
|
108
|
+
$scope.value_type_choices = _.sortBy([
|
109
|
+
{name: "string", title: "String"},
|
110
|
+
{name: "numeric", title: "Numeric"},
|
111
|
+
{name: "email", title: "Email"},
|
112
|
+
], "title");
|
109
113
|
if( "id" in $routeParams ){
|
110
114
|
$scope.obj_id = $routeParams.id;
|
111
115
|
$scope.editing = true;
|
@@ -118,6 +122,8 @@ ContactFields.controller("AddContactFieldController", ["Restangular", "$scope",
|
|
118
122
|
.then(function(data) {
|
119
123
|
|
120
124
|
$scope.name = data.name;
|
125
|
+
$scope.value_type = data.value_type;
|
126
|
+
$scope.validation_rules = data.validation_rules;
|
121
127
|
}, function(data){
|
122
128
|
catch_error(data);
|
123
129
|
});
|
@@ -143,6 +149,8 @@ ContactFields.controller("AddContactFieldController", ["Restangular", "$scope",
|
|
143
149
|
$scope.save = function(save_another){
|
144
150
|
var contact_field = {contact_field: {
|
145
151
|
name: $scope.name,
|
152
|
+
value_type: $scope.value_type,
|
153
|
+
validation_rules: $scope.validation_rules,
|
146
154
|
__res__: 0
|
147
155
|
}};
|
148
156
|
if (($scope.obj_id) && (is_copy === false)) {
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class API::V1::ContactDetailsController < Faalis::APIController
|
2
|
+
|
3
|
+
def destroy
|
4
|
+
ids = params[:id].split(",")
|
5
|
+
@contact_details = ::ContactDetails.where(:id => ids)
|
6
|
+
authorize! :destroy, ContactDetails
|
7
|
+
@contact_details.destroy_all
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_resource
|
11
|
+
@contact_details = ::ContactDetails.new(resource_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_params
|
15
|
+
params.require(:contact_details).permit(:id, :details_value)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -8,7 +8,7 @@ class API::V1::ContactFieldsController < Faalis::APIController
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def create
|
11
|
-
|
11
|
+
|
12
12
|
if @contact_field.save
|
13
13
|
respond_with(@contact_field)
|
14
14
|
else
|
@@ -23,7 +23,7 @@ class API::V1::ContactFieldsController < Faalis::APIController
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def update
|
26
|
-
|
26
|
+
|
27
27
|
|
28
28
|
if @contact_field.update(resource_params)
|
29
29
|
respond_with(@contact_field)
|
@@ -46,7 +46,7 @@ class API::V1::ContactFieldsController < Faalis::APIController
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def resource_params
|
49
|
-
params.require(:contact_field).permit(:id, :name)
|
49
|
+
params.require(:contact_field).permit(:id, :name, :value_type, :validation_rules)
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
@@ -8,24 +8,7 @@ class API::V1::ContactsController < Faalis::APIController
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def create
|
11
|
-
|
12
|
-
details_list = []
|
13
|
-
details.each do |detail|
|
14
|
-
contact_detail = ContactDetails.create!(:detail_field => detail[:field],
|
15
|
-
:detail_type => detail[:type],
|
16
|
-
:detail_value => detail[:value])
|
17
|
-
details_list << contact_detail
|
18
|
-
end
|
19
|
-
|
20
|
-
@contact.details = details_list
|
21
|
-
|
22
|
-
if @contact.save
|
23
|
-
respond_with(@contact)
|
24
|
-
else
|
25
|
-
respond_to do |format|
|
26
|
-
format.json { render :json => {:fields => @contact.errors}, :status => :unprocessable_entity }
|
27
|
-
end
|
28
|
-
end
|
11
|
+
create_or_update(:create)
|
29
12
|
end
|
30
13
|
|
31
14
|
def show
|
@@ -33,24 +16,7 @@ class API::V1::ContactsController < Faalis::APIController
|
|
33
16
|
end
|
34
17
|
|
35
18
|
def update
|
36
|
-
|
37
|
-
details_list = []
|
38
|
-
details.each do |detail|
|
39
|
-
contact_detail = ContactDetails.create!(:detail_field => detail[:field],
|
40
|
-
:detail_type => detail[:type],
|
41
|
-
:detail_value => detail[:value])
|
42
|
-
details_list << contact_detail
|
43
|
-
end
|
44
|
-
|
45
|
-
@contact.details = details_list
|
46
|
-
|
47
|
-
if @contact.update(resource_params)
|
48
|
-
respond_with(@contact)
|
49
|
-
else
|
50
|
-
respond_to do |format|
|
51
|
-
format.json { render :json => {:fields => @contact.errors}, :status => :unprocessable_entity }
|
52
|
-
end
|
53
|
-
end
|
19
|
+
create_or_update(:update)
|
54
20
|
end
|
55
21
|
|
56
22
|
def destroy
|
@@ -68,4 +34,76 @@ class API::V1::ContactsController < Faalis::APIController
|
|
68
34
|
params.require(:contact).permit(:id, :prefix, :first_name, :middle_name, :last_name, :suffix, :organization, :is_organization)
|
69
35
|
end
|
70
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_or_update(action)
|
40
|
+
details = params[:contact][:details] || []
|
41
|
+
details_list = []
|
42
|
+
details_errors = []
|
43
|
+
valid = true
|
44
|
+
|
45
|
+
details.each do |detail|
|
46
|
+
|
47
|
+
contact_detail = ContactDetails.find_or_initialize_by(:detail_field_id => detail[:field],
|
48
|
+
:detail_type => detail[:type],
|
49
|
+
:detail_value => detail[:value])
|
50
|
+
|
51
|
+
if not contact_detail.valid?
|
52
|
+
details_errors << contact_detail.errors
|
53
|
+
valid = false
|
54
|
+
else
|
55
|
+
details_errors << {}
|
56
|
+
details_list << contact_detail
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if valid
|
61
|
+
details_list.each { |x| x.save }
|
62
|
+
@contact.details = details_list
|
63
|
+
end
|
64
|
+
|
65
|
+
result = @contact.update(resource_params) if action == :update
|
66
|
+
result = @contact.save if action == :create
|
67
|
+
|
68
|
+
if result and valid
|
69
|
+
respond_with(@contact)
|
70
|
+
else
|
71
|
+
errors = get_details_error(@contact, details_errors)
|
72
|
+
respond_to do |format|
|
73
|
+
format.json { render :json => errors, :status => :unprocessable_entity }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_details_error(contact, gerrors)
|
81
|
+
errors = {:fields => contact.errors}
|
82
|
+
counter = 0
|
83
|
+
|
84
|
+
contact.details.each do |detail|
|
85
|
+
if not detail.errors.empty?
|
86
|
+
detail.errors.each do |key, value|
|
87
|
+
errors[:fields]["#{key}_#{counter}".to_sym] = value
|
88
|
+
if errors[:fields]["#{key}_#{counter}".to_sym].length > 1
|
89
|
+
errors[:fields]["#{key}_#{counter}".to_sym].uniq!
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
counter += 1
|
94
|
+
end
|
95
|
+
|
96
|
+
counter = 0
|
97
|
+
gerrors.each do |err|
|
98
|
+
err.each do |key, value|
|
99
|
+
errors[:fields]["#{key}_#{counter}".to_sym] = value
|
100
|
+
if errors[:fields]["#{key}_#{counter}".to_sym].length > 1
|
101
|
+
errors[:fields]["#{key}_#{counter}".to_sym].uniq!
|
102
|
+
end
|
103
|
+
end
|
104
|
+
counter += 1
|
105
|
+
end
|
106
|
+
errors
|
107
|
+
end
|
108
|
+
|
71
109
|
end
|
data/app/models/contact.rb
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
class ContactDetails < ActiveRecord::Base
|
2
|
+
@already_validate = false
|
3
|
+
|
2
4
|
belongs_to :contact
|
5
|
+
belongs_to :field, :class_name => "ContactField"
|
6
|
+
|
7
|
+
validates :detail_field_id, :presence => true
|
8
|
+
validates :detail_type, :presence => true
|
9
|
+
validates :detail_value, :presence => true
|
10
|
+
|
11
|
+
validate :validate_value
|
12
|
+
|
3
13
|
|
14
|
+
def validate_value
|
15
|
+
require 'json'
|
16
|
+
if @already_validate
|
17
|
+
return
|
18
|
+
end
|
4
19
|
|
20
|
+
print "----" * 1000
|
21
|
+
if detail_field_id.nil?
|
22
|
+
errors[:detail_field] = _("Field can not be empty.")
|
23
|
+
return
|
24
|
+
end
|
25
|
+
rules = ContactField.find(detail_field_id).validation_rules
|
26
|
+
params = JSON.parse(rules).deep_symbolize_keys
|
27
|
+
@already_validate = true
|
28
|
+
begin
|
29
|
+
self.class.validates :detail_value, **params
|
30
|
+
rescue ArgumentError => e
|
31
|
+
errors[:error] = _("Field validation rules is not valid!")
|
32
|
+
end
|
33
|
+
end
|
5
34
|
end
|
data/app/models/contact_field.rb
CHANGED
@@ -4,6 +4,14 @@
|
|
4
4
|
<b translate>Name :</b> {{object.name}}
|
5
5
|
</p>
|
6
6
|
|
7
|
+
<p>
|
8
|
+
<b translate>Value_type :</b> {{object.value_type}}
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b translate>Validation_rules :</b> {{object.validation_rules}}
|
13
|
+
</p>
|
14
|
+
|
7
15
|
<ul class="button-group float-right">
|
8
16
|
<a ng-href="#/contact_fields/{{ object.id }}/edit" class="small">
|
9
17
|
<span class="fa fa-edit"></span> <span translated>Edit</span>
|
@@ -20,6 +20,30 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
|
24
|
+
<div class="small-4 columns float-left small-offset-2">
|
25
|
+
<label><span translate>Value type</span> :</label>
|
26
|
+
|
27
|
+
<select id="id_value_type" ui-select2="select2options" ng-model="value_type" name="value_type" >
|
28
|
+
<option ng-repeat="item in value_type_choices" value="{{ item.name }}" title="{{ item.title }}" ng-selected="value_type === item.name">{{ item.title }}</option>
|
29
|
+
</select>
|
30
|
+
|
31
|
+
<small id="id_value_type_msg"></small>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
|
36
|
+
<div class="row">
|
37
|
+
<div class="small-4 columns ">
|
38
|
+
<label><span translate>Validation rules</span> :</label>
|
39
|
+
|
40
|
+
<textarea id="id_validation_rules" class="rounded" ng-model="validation_rules" name="validation_rules" ></textarea>
|
41
|
+
|
42
|
+
<small id="id_validation_rules_msg"></small>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
|
46
|
+
|
23
47
|
</fieldset>
|
24
48
|
</form>
|
25
49
|
|
@@ -0,0 +1 @@
|
|
1
|
+
json.msg _("Items removed successfully.")
|
@@ -1,2 +1,2 @@
|
|
1
|
-
json.extract! @contact_field, :id, :name
|
1
|
+
json.extract! @contact_field, :id, :name, :value_type, :validation_rules
|
2
2
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
json.extract! @contact_field, :id, :name
|
1
|
+
json.extract! @contact_field, :id, :name, :value_type, :validation_rules
|
2
2
|
|
@@ -2,6 +2,6 @@ json.extract! @contact, :id, :prefix, :first_name, :middle_name, :last_name, :su
|
|
2
2
|
json.details @contact.details do |detail|
|
3
3
|
json.id detail.id
|
4
4
|
json.type detail.detail_type
|
5
|
-
json.field detail.
|
5
|
+
json.field detail.detail_field_id
|
6
6
|
json.value detail.detail_value
|
7
7
|
end
|
data/config/routes.rb
CHANGED
data/lib/tasks/build.rake
CHANGED
@@ -7,7 +7,7 @@ namespace :build do
|
|
7
7
|
|
8
8
|
desc "Create contact fields scaffold"
|
9
9
|
task :fields do
|
10
|
-
system "rails g faalis:js_scaffold contact_field name:string --no-bulk --required name"
|
10
|
+
system "rails g faalis:js_scaffold contact_field name:string value_type:in:string,numeric,email validation_rules:text --no-bulk --required name --path faalis_contacts"
|
11
11
|
end
|
12
12
|
|
13
13
|
desc "Create contact type scaffold"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faalis_contacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Rahmani
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -145,12 +145,14 @@ files:
|
|
145
145
|
- app/views/api/v1/contacts/create.json.jbuilder
|
146
146
|
- app/views/api/v1/contacts/update.json.jbuilder
|
147
147
|
- app/views/api/v1/contacts/index.json.jbuilder
|
148
|
+
- app/views/api/v1/contact_details/destroy.json.jbuilder
|
148
149
|
- app/assets/javascripts/faalis_contacts/application.js
|
149
150
|
- app/assets/javascripts/faalis_contacts/modules/contact.js
|
150
151
|
- app/assets/javascripts/faalis_contacts/modules/contact_type.js
|
151
152
|
- app/assets/javascripts/faalis_contacts/modules/contact_field.js
|
152
153
|
- app/controllers/api/v1/contact_fields_controller.rb
|
153
154
|
- app/controllers/api/v1/contact_types_controller.rb
|
155
|
+
- app/controllers/api/v1/contact_details_controller.rb
|
154
156
|
- app/controllers/api/v1/contacts_controller.rb
|
155
157
|
- config/routes.rb
|
156
158
|
- db/migrate/20140113071029_create_contact_fields.rb
|