faalis_contacts 0.1.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 +7 -0
- data/LICENSE +339 -0
- data/README.md +3 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/faalis_contacts/application.js +1 -0
- data/app/assets/javascripts/faalis_contacts/modules/contact.js +360 -0
- data/app/assets/javascripts/faalis_contacts/modules/contact_field.js +180 -0
- data/app/assets/javascripts/faalis_contacts/modules/contact_type.js +180 -0
- data/app/controllers/api/v1/contact_fields_controller.rb +52 -0
- data/app/controllers/api/v1/contact_types_controller.rb +52 -0
- data/app/controllers/api/v1/contacts_controller.rb +71 -0
- data/app/models/contact.rb +6 -0
- data/app/models/contact_details.rb +5 -0
- data/app/models/contact_field.rb +2 -0
- data/app/models/contact_type.rb +2 -0
- data/app/views/angularjs_templates/contact/details.html +36 -0
- data/app/views/angularjs_templates/contact/index.html +62 -0
- data/app/views/angularjs_templates/contact/new.html +120 -0
- data/app/views/angularjs_templates/contact_field/details.html +12 -0
- data/app/views/angularjs_templates/contact_field/index.html +9 -0
- data/app/views/angularjs_templates/contact_field/new.html +37 -0
- data/app/views/angularjs_templates/contact_type/details.html +12 -0
- data/app/views/angularjs_templates/contact_type/index.html +9 -0
- data/app/views/angularjs_templates/contact_type/new.html +37 -0
- data/app/views/api/v1/contact_fields/create.json.jbuilder +2 -0
- data/app/views/api/v1/contact_fields/destroy.json.jbuilder +1 -0
- data/app/views/api/v1/contact_fields/index.json.jbuilder +3 -0
- data/app/views/api/v1/contact_fields/show.json.jbuilder +2 -0
- data/app/views/api/v1/contact_fields/update.json.jbuilder +2 -0
- data/app/views/api/v1/contact_types/create.json.jbuilder +2 -0
- data/app/views/api/v1/contact_types/destroy.json.jbuilder +1 -0
- data/app/views/api/v1/contact_types/index.json.jbuilder +3 -0
- data/app/views/api/v1/contact_types/show.json.jbuilder +2 -0
- data/app/views/api/v1/contact_types/update.json.jbuilder +2 -0
- data/app/views/api/v1/contacts/create.json.jbuilder +2 -0
- data/app/views/api/v1/contacts/destroy.json.jbuilder +1 -0
- data/app/views/api/v1/contacts/index.json.jbuilder +9 -0
- data/app/views/api/v1/contacts/show.json.jbuilder +7 -0
- data/app/views/api/v1/contacts/update.json.jbuilder +2 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20140109115319_create_contacts.rb +15 -0
- data/db/migrate/20140111082843_create_contact_details.rb +13 -0
- data/db/migrate/20140113071029_create_contact_fields.rb +9 -0
- data/db/migrate/20140113071738_create_contact_types.rb +9 -0
- data/db/seeds.rb +9 -0
- data/lib/faalis_contacts.rb +6 -0
- data/lib/faalis_contacts/engine.rb +17 -0
- data/lib/faalis_contacts/version.rb +3 -0
- data/lib/tasks/build.rake +18 -0
- data/lib/tasks/faalis_contacts_tasks.rake +4 -0
- metadata +193 -0
@@ -0,0 +1,180 @@
|
|
1
|
+
|
2
|
+
// ContactFields Module
|
3
|
+
var ContactFields = angular.module("ContactField", ["ListView", "Filter", "Anim"]);
|
4
|
+
|
5
|
+
// ContactFields configuration section ---------------------------
|
6
|
+
ContactFields.config(["$routeProvider", function($routeProvider){
|
7
|
+
|
8
|
+
// Add any route you need here
|
9
|
+
$routeProvider.
|
10
|
+
when("/contact_fields", {
|
11
|
+
templateUrl: template("contact_field/index"),
|
12
|
+
controller: "ContactFieldController"
|
13
|
+
}).
|
14
|
+
when("/contact_fields/new",{
|
15
|
+
templateUrl: template("contact_field/new"),
|
16
|
+
controller: "AddContactFieldController"
|
17
|
+
}).
|
18
|
+
when("/contact_fields/:id/edit",{
|
19
|
+
templateUrl: template("contact_field/new"),
|
20
|
+
controller: "AddContactFieldController"
|
21
|
+
});
|
22
|
+
|
23
|
+
}]);
|
24
|
+
|
25
|
+
// ContactField index controller -------------------------------------------------------
|
26
|
+
// This controller is responsible for list page (index)
|
27
|
+
ContactFields.controller("ContactFieldController", ["$scope", "gettext", "Restangular", "catch_error", "$location",
|
28
|
+
function($scope, gettext, API, catch_error, $location){
|
29
|
+
|
30
|
+
$scope.filter_config = {
|
31
|
+
list: API.all("contact_fields")
|
32
|
+
};
|
33
|
+
$scope.contact_fields = [];
|
34
|
+
|
35
|
+
|
36
|
+
// details_template is the address of template which should load for
|
37
|
+
// each item details section
|
38
|
+
$scope.details_template = template("contact_field/details");
|
39
|
+
|
40
|
+
// Buttons for top of the list-view
|
41
|
+
$scope.buttons = [
|
42
|
+
{
|
43
|
+
title: gettext("New"),
|
44
|
+
icon: "fa fa-plus",
|
45
|
+
classes: "btn tiny green",
|
46
|
+
route: "#contact_fields/new"
|
47
|
+
|
48
|
+
},
|
49
|
+
{
|
50
|
+
title: gettext("Duplicate"),
|
51
|
+
icon: "fa fa-files-o",
|
52
|
+
classes: "btn tiny red",
|
53
|
+
action: function(){
|
54
|
+
var selected = _.find($scope.contact_fields, function(x){
|
55
|
+
return x.is_selected === true;
|
56
|
+
});
|
57
|
+
|
58
|
+
if (selected === undefined ) {
|
59
|
+
error_message(gettext("You should only select one item to copy."));
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
$location.path("/contact_fields/-" + selected.id + "/edit");
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
];
|
68
|
+
/*
|
69
|
+
* On delete event handler - `items` is an array of objects to delete
|
70
|
+
*/
|
71
|
+
$scope.on_delete = function(items){
|
72
|
+
|
73
|
+
var query = [];
|
74
|
+
items.forEach(function(item){
|
75
|
+
query.push(item.id);
|
76
|
+
});
|
77
|
+
|
78
|
+
API.all("contact_fields").customDELETE(query.join(","))
|
79
|
+
.then(function(data) {
|
80
|
+
|
81
|
+
$scope.contact_fields = _.filter($scope.contact_fields, function(x){
|
82
|
+
return !(query.indexOf(x.id) != -1);
|
83
|
+
});
|
84
|
+
success_message(data.msg);
|
85
|
+
}, function(data){
|
86
|
+
catch_error(data);
|
87
|
+
});
|
88
|
+
|
89
|
+
};
|
90
|
+
/*
|
91
|
+
API.all("contact_fields").getList()
|
92
|
+
.then(function(data){
|
93
|
+
$scope.contact_fields = data;
|
94
|
+
}, function(data){
|
95
|
+
catch_error(data);
|
96
|
+
});
|
97
|
+
*/
|
98
|
+
}]);
|
99
|
+
|
100
|
+
ContactFields.controller("AddContactFieldController", ["Restangular", "$scope", "$location", "$routeParams", "gettext", "catch_error", function(API, $scope, $location, $routeParams, gettext, catch_error){
|
101
|
+
|
102
|
+
$scope.select2options = {};
|
103
|
+
$scope.editing = false;
|
104
|
+
$scope.obj_id = null;
|
105
|
+
var is_copy = false;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
if( "id" in $routeParams ){
|
110
|
+
$scope.obj_id = $routeParams.id;
|
111
|
+
$scope.editing = true;
|
112
|
+
if ($scope.obj_id < 0) {
|
113
|
+
is_copy = true;
|
114
|
+
$scope.obj_id = $scope.obj_id * -1;
|
115
|
+
}
|
116
|
+
|
117
|
+
var obj = API.one("contact_fields", $scope.obj_id).get()
|
118
|
+
.then(function(data) {
|
119
|
+
|
120
|
+
$scope.name = data.name;
|
121
|
+
}, function(data){
|
122
|
+
catch_error(data);
|
123
|
+
});
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
$scope.have = function(field, obj_id) {
|
129
|
+
var tmp = _.where($scope[field], {id: obj_id});
|
130
|
+
if (tmp.length > 0) {
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
return false;
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
$scope.cancel = function(){
|
139
|
+
$(".form input").val("");
|
140
|
+
$location.path("contact_fields");
|
141
|
+
};
|
142
|
+
|
143
|
+
$scope.save = function(save_another){
|
144
|
+
var contact_field = {contact_field: {
|
145
|
+
name: $scope.name,
|
146
|
+
__res__: 0
|
147
|
+
}};
|
148
|
+
if (($scope.obj_id) && (is_copy === false)) {
|
149
|
+
|
150
|
+
API.one("contact_fields", $scope.obj_id).patch(contact_field)
|
151
|
+
.then(function(){
|
152
|
+
success_message(gettext("ContactField updated successfully."));
|
153
|
+
if (save_another) {
|
154
|
+
$(".form input").val("");
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
$location.path("contact_fields");
|
158
|
+
}
|
159
|
+
}, function(data){
|
160
|
+
catch_error(data);
|
161
|
+
});
|
162
|
+
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
API.all("contact_fields").customPOST(contact_field, "").then(function(){
|
166
|
+
success_message(gettext("ContactField created successfully."));
|
167
|
+
if (save_another) {
|
168
|
+
$(".form input").val("");
|
169
|
+
}
|
170
|
+
else {
|
171
|
+
$location.path("contact_fields");
|
172
|
+
}
|
173
|
+
}, function(data){
|
174
|
+
catch_error(data);
|
175
|
+
});
|
176
|
+
}
|
177
|
+
|
178
|
+
};
|
179
|
+
}]);
|
180
|
+
|
@@ -0,0 +1,180 @@
|
|
1
|
+
|
2
|
+
// ContactTypes Module
|
3
|
+
var ContactTypes = angular.module("ContactType", ["ListView", "Filter", "Anim"]);
|
4
|
+
|
5
|
+
// ContactTypes configuration section ---------------------------
|
6
|
+
ContactTypes.config(["$routeProvider", function($routeProvider){
|
7
|
+
|
8
|
+
// Add any route you need here
|
9
|
+
$routeProvider.
|
10
|
+
when("/contact_types", {
|
11
|
+
templateUrl: template("contact_type/index"),
|
12
|
+
controller: "ContactTypeController"
|
13
|
+
}).
|
14
|
+
when("/contact_types/new",{
|
15
|
+
templateUrl: template("contact_type/new"),
|
16
|
+
controller: "AddContactTypeController"
|
17
|
+
}).
|
18
|
+
when("/contact_types/:id/edit",{
|
19
|
+
templateUrl: template("contact_type/new"),
|
20
|
+
controller: "AddContactTypeController"
|
21
|
+
});
|
22
|
+
|
23
|
+
}]);
|
24
|
+
|
25
|
+
// ContactType index controller -------------------------------------------------------
|
26
|
+
// This controller is responsible for list page (index)
|
27
|
+
ContactTypes.controller("ContactTypeController", ["$scope", "gettext", "Restangular", "catch_error", "$location",
|
28
|
+
function($scope, gettext, API, catch_error, $location){
|
29
|
+
|
30
|
+
$scope.filter_config = {
|
31
|
+
list: API.all("contact_types")
|
32
|
+
};
|
33
|
+
$scope.contact_types = [];
|
34
|
+
|
35
|
+
|
36
|
+
// details_template is the address of template which should load for
|
37
|
+
// each item details section
|
38
|
+
$scope.details_template = template("contact_type/details");
|
39
|
+
|
40
|
+
// Buttons for top of the list-view
|
41
|
+
$scope.buttons = [
|
42
|
+
{
|
43
|
+
title: gettext("New"),
|
44
|
+
icon: "fa fa-plus",
|
45
|
+
classes: "btn tiny green",
|
46
|
+
route: "#contact_types/new"
|
47
|
+
|
48
|
+
},
|
49
|
+
{
|
50
|
+
title: gettext("Duplicate"),
|
51
|
+
icon: "fa fa-files-o",
|
52
|
+
classes: "btn tiny red",
|
53
|
+
action: function(){
|
54
|
+
var selected = _.find($scope.contact_types, function(x){
|
55
|
+
return x.is_selected === true;
|
56
|
+
});
|
57
|
+
|
58
|
+
if (selected === undefined ) {
|
59
|
+
error_message(gettext("You should only select one item to copy."));
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
$location.path("/contact_types/-" + selected.id + "/edit");
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
];
|
68
|
+
/*
|
69
|
+
* On delete event handler - `items` is an array of objects to delete
|
70
|
+
*/
|
71
|
+
$scope.on_delete = function(items){
|
72
|
+
|
73
|
+
var query = [];
|
74
|
+
items.forEach(function(item){
|
75
|
+
query.push(item.id);
|
76
|
+
});
|
77
|
+
|
78
|
+
API.all("contact_types").customDELETE(query.join(","))
|
79
|
+
.then(function(data) {
|
80
|
+
|
81
|
+
$scope.contact_types = _.filter($scope.contact_types, function(x){
|
82
|
+
return !(query.indexOf(x.id) != -1);
|
83
|
+
});
|
84
|
+
success_message(data.msg);
|
85
|
+
}, function(data){
|
86
|
+
catch_error(data);
|
87
|
+
});
|
88
|
+
|
89
|
+
};
|
90
|
+
/*
|
91
|
+
API.all("contact_types").getList()
|
92
|
+
.then(function(data){
|
93
|
+
$scope.contact_types = data;
|
94
|
+
}, function(data){
|
95
|
+
catch_error(data);
|
96
|
+
});
|
97
|
+
*/
|
98
|
+
}]);
|
99
|
+
|
100
|
+
ContactTypes.controller("AddContactTypeController", ["Restangular", "$scope", "$location", "$routeParams", "gettext", "catch_error", function(API, $scope, $location, $routeParams, gettext, catch_error){
|
101
|
+
|
102
|
+
$scope.select2options = {};
|
103
|
+
$scope.editing = false;
|
104
|
+
$scope.obj_id = null;
|
105
|
+
var is_copy = false;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
if( "id" in $routeParams ){
|
110
|
+
$scope.obj_id = $routeParams.id;
|
111
|
+
$scope.editing = true;
|
112
|
+
if ($scope.obj_id < 0) {
|
113
|
+
is_copy = true;
|
114
|
+
$scope.obj_id = $scope.obj_id * -1;
|
115
|
+
}
|
116
|
+
|
117
|
+
var obj = API.one("contact_types", $scope.obj_id).get()
|
118
|
+
.then(function(data) {
|
119
|
+
|
120
|
+
$scope.name = data.name;
|
121
|
+
}, function(data){
|
122
|
+
catch_error(data);
|
123
|
+
});
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
$scope.have = function(field, obj_id) {
|
129
|
+
var tmp = _.where($scope[field], {id: obj_id});
|
130
|
+
if (tmp.length > 0) {
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
return false;
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
$scope.cancel = function(){
|
139
|
+
$(".form input").val("");
|
140
|
+
$location.path("contact_types");
|
141
|
+
};
|
142
|
+
|
143
|
+
$scope.save = function(save_another){
|
144
|
+
var contact_type = {contact_type: {
|
145
|
+
name: $scope.name,
|
146
|
+
__res__: 0
|
147
|
+
}};
|
148
|
+
if (($scope.obj_id) && (is_copy === false)) {
|
149
|
+
|
150
|
+
API.one("contact_types", $scope.obj_id).patch(contact_type)
|
151
|
+
.then(function(){
|
152
|
+
success_message(gettext("ContactType updated successfully."));
|
153
|
+
if (save_another) {
|
154
|
+
$(".form input").val("");
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
$location.path("contact_types");
|
158
|
+
}
|
159
|
+
}, function(data){
|
160
|
+
catch_error(data);
|
161
|
+
});
|
162
|
+
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
API.all("contact_types").customPOST(contact_type, "").then(function(){
|
166
|
+
success_message(gettext("ContactType created successfully."));
|
167
|
+
if (save_another) {
|
168
|
+
$(".form input").val("");
|
169
|
+
}
|
170
|
+
else {
|
171
|
+
$location.path("contact_types");
|
172
|
+
}
|
173
|
+
}, function(data){
|
174
|
+
catch_error(data);
|
175
|
+
});
|
176
|
+
}
|
177
|
+
|
178
|
+
};
|
179
|
+
}]);
|
180
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class API::V1::ContactFieldsController < Faalis::APIController
|
2
|
+
before_filter :build_resource, :only => :create
|
3
|
+
load_and_authorize_resource :except => [:destory]
|
4
|
+
|
5
|
+
# GET /api/v1/contact_fields
|
6
|
+
def index
|
7
|
+
respond_with(@contact_fields)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
|
12
|
+
if @contact_field.save
|
13
|
+
respond_with(@contact_field)
|
14
|
+
else
|
15
|
+
respond_to do |format|
|
16
|
+
format.json { render :json => {:fields => @contact_field.errors}, :status => :unprocessable_entity }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
respond_with(@contact_field)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
|
27
|
+
|
28
|
+
if @contact_field.update(resource_params)
|
29
|
+
respond_with(@contact_field)
|
30
|
+
else
|
31
|
+
respond_to do |format|
|
32
|
+
format.json { render :json => {:fields => @contact_field.errors}, :status => :unprocessable_entity }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
ids = params[:id].split(",")
|
39
|
+
@contact_fields = ::ContactField.where(:id => ids)
|
40
|
+
authorize! :destroy, @contact_fields
|
41
|
+
@contact_fields.destroy_all
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_resource
|
45
|
+
@contact_field = ::ContactField.new(resource_params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_params
|
49
|
+
params.require(:contact_field).permit(:id, :name)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class API::V1::ContactTypesController < Faalis::APIController
|
2
|
+
before_filter :build_resource, :only => :create
|
3
|
+
load_and_authorize_resource :except => [:destory]
|
4
|
+
|
5
|
+
# GET /api/v1/contact_types
|
6
|
+
def index
|
7
|
+
respond_with(@contact_types)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
|
12
|
+
if @contact_type.save
|
13
|
+
respond_with(@contact_type)
|
14
|
+
else
|
15
|
+
respond_to do |format|
|
16
|
+
format.json { render :json => {:fields => @contact_type.errors}, :status => :unprocessable_entity }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
respond_with(@contact_type)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
|
27
|
+
|
28
|
+
if @contact_type.update(resource_params)
|
29
|
+
respond_with(@contact_type)
|
30
|
+
else
|
31
|
+
respond_to do |format|
|
32
|
+
format.json { render :json => {:fields => @contact_type.errors}, :status => :unprocessable_entity }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
ids = params[:id].split(",")
|
39
|
+
@contact_types = ContactType.where(:id => ids)
|
40
|
+
authorize! :destroy, @contact_types
|
41
|
+
@contact_types.destroy_all
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_resource
|
45
|
+
@contact_type = ContactType.new(resource_params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_params
|
49
|
+
params.require(:contact_type).permit(:id, :name)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|