faalis 1.0.0.alpha1 → 1.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/Rakefile +6 -2
- data/app/assets/javascripts/faalis/angular-manifest.js +3 -0
- data/app/assets/javascripts/faalis/application.js +0 -1
- data/app/assets/javascripts/faalis/dashboard/app.js +20 -6
- data/app/assets/javascripts/faalis/dashboard/application.js.erb +5 -1
- data/app/assets/javascripts/faalis/dashboard/controllers/group.js.coffee +42 -0
- data/app/assets/javascripts/faalis/dashboard/functions.js.erb +20 -0
- data/app/assets/javascripts/faalis/dashboard/init.js +1 -1
- data/app/assets/javascripts/faalis/dashboard/lib/button.js.coffee +17 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers.js.coffee +11 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers/base_controller.js.coffee +14 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers/generic_add_controller.js.coffee +33 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers/generic_index_controller.js.coffee +85 -0
- data/app/assets/javascripts/faalis/dashboard/lib/fields/base.js.coffee +6 -0
- data/app/assets/javascripts/faalis/dashboard/lib/fields/has_many_field.js.coffee +4 -0
- data/app/assets/javascripts/faalis/dashboard/lib/fields/string_field.js.coffee +2 -0
- data/app/assets/javascripts/faalis/dashboard/lib/resource.js.coffee +147 -0
- data/app/assets/javascripts/faalis/dashboard/modules/auth/auth.js +5 -3
- data/app/assets/javascripts/faalis/dashboard/modules/auth/profile.js +6 -5
- data/app/assets/javascripts/faalis/dashboard/modules/auth/user.js +12 -10
- data/app/assets/javascripts/faalis/dashboard/modules/conversations.js +2 -1
- data/app/assets/javascripts/faalis/dashboard/modules/fields/#image.js# +43 -0
- data/app/assets/javascripts/faalis/dashboard/modules/fields/date.js +51 -0
- data/app/assets/javascripts/faalis/dashboard/modules/fields/datetime.js +26 -15
- data/app/assets/javascripts/faalis/dashboard/modules/fields/fields.js +3 -1
- data/app/assets/javascripts/faalis/dashboard/modules/fields/file.js +43 -0
- data/app/assets/javascripts/faalis/dashboard/modules/fields/image.js +33 -46
- data/app/assets/javascripts/faalis/dashboard/modules/fields/relation.js +7 -4
- data/app/assets/javascripts/faalis/dashboard/modules/fields/tag.js +5 -11
- data/app/assets/javascripts/faalis/dashboard/modules/fields/time.js +34 -122
- data/app/assets/javascripts/faalis/dashboard/modules/logs.js +5 -4
- data/app/assets/javascripts/faalis/dashboard/modules/permissions.js.coffee +38 -0
- data/app/assets/javascripts/faalis/dashboard/resources/group_resource.js.coffee +8 -0
- data/app/assets/javascripts/faalis/dashboard/resources/permission_resource.js.coffee +6 -0
- data/app/assets/javascripts/faalis/dashboard/services/api.js.coffee +73 -0
- data/app/assets/javascripts/faalis/dashboard/services/resource_factory.js.coffee +48 -0
- data/app/assets/javascripts/faalis/dashboard/services/user.js.coffee +4 -0
- data/app/assets/javascripts/faalis/dashboard/variables.js.erb +5 -0
- data/app/assets/javascripts/faalis/{locales → locale}/en.json +0 -0
- data/app/assets/javascripts/faalis/{locales → locale}/fa.json +0 -0
- data/app/assets/javascripts/faalis/{locales → locale}/translations.fa.js +0 -0
- data/app/controllers/faalis/api/v1/groups_controller.rb +53 -57
- data/app/controllers/faalis/api/v1/permissions_controller.rb +29 -12
- data/app/controllers/faalis/api_controller.rb +19 -12
- data/app/controllers/faalis/application_controller.rb +8 -7
- data/app/controllers/faalis/dashboard_controller.rb +5 -11
- data/app/models/faalis/{user → concerns/user}/auth_definitions.rb +6 -1
- data/app/models/faalis/{user → concerns/user}/mongoid_fields.rb +8 -2
- data/app/models/faalis/concerns/user/permission.rb +24 -0
- data/app/models/faalis/concerns/user/user_roles.rb +20 -0
- data/app/models/faalis/group.rb +13 -15
- data/app/models/faalis/permission.rb +15 -1
- data/app/models/faalis/user.rb +44 -20
- data/app/policies/faalis/admin_only_policy.rb +66 -0
- data/app/policies/faalis/application_policy.rb +40 -0
- data/app/policies/faalis/group_policy.rb +8 -0
- data/app/policies/faalis/user_policy.rb +9 -0
- data/app/views/{angularjs_templates → angular}/auth/groups/details.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/groups/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/groups/new.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/profile/edit.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/users/details.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/users/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/users/new.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/details.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/new.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/show.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/show_details.html +0 -0
- data/app/views/angular/faalis/views/generic_add_view.html.slim +5 -0
- data/app/views/{angularjs_templates → angular}/fields/boolean/boolean.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/control-combo/control-list.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/datetime/datetime.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/datetime/time.html +0 -0
- data/app/views/angular/fields/file/file.html.slim +0 -0
- data/app/views/{angularjs_templates → angular}/fields/float/float.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/image/image.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/integer/integer.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/relation/relation.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/string/string.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/tag/tag.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/text/text.html +0 -0
- data/app/views/{angularjs_templates → angular}/filter/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/locale/fa.po +0 -0
- data/app/views/{angularjs_templates → angular}/locale/templates.pot +0 -0
- data/app/views/{angularjs_templates → angular}/logs/index.html +0 -0
- data/app/views/angular/modules.html +0 -0
- data/app/views/{angularjs_templates → angular}/nav.html.erb +0 -0
- data/app/views/faalis/api/v1/groups/index.json.jbuilder +1 -1
- data/app/views/faalis/api/v1/permissions/index.json.jbuilder +1 -1
- data/app/views/faalis/dashboard/index.html.erb +1 -1
- data/app/views/layouts/faalis/application.html.erb +1 -1
- data/config/routes.rb +1 -7
- data/config/spring.rb +1 -0
- data/db/migrate/20131013091000_devise_create_faalis_users.rb +4 -4
- data/db/migrate/20131020124701_create_faalis_groups.rb +3 -0
- data/db/migrate/20131021170923_create_faalis_permissions.rb +2 -0
- data/db/seeds.rb +15 -13
- data/lib/faalis.rb +2 -2
- data/lib/faalis/concerns/authorizable.rb +1 -0
- data/lib/faalis/engine.rb +15 -16
- data/lib/faalis/{extensions.rb → extension.rb} +1 -1
- data/lib/faalis/{extensions → extension}/base.rb +0 -0
- data/lib/faalis/fake_assets.rb +2 -0
- data/lib/faalis/generators/concerns.rb +1 -1
- data/lib/faalis/generators/concerns/angular.rb +1 -1
- data/lib/faalis/generators/concerns/bulk.rb +1 -2
- data/lib/faalis/generators/concerns/input_file.rb +49 -0
- data/lib/faalis/generators/concerns/resource_fields.rb +4 -0
- data/lib/faalis/generators/concerns/tabs.rb +1 -1
- data/lib/faalis/generators/dashboard_scaffold.rb +3 -1
- data/lib/faalis/i18n.rb +1 -0
- data/lib/faalis/route.rb +26 -9
- data/lib/faalis/version.rb +1 -1
- data/lib/faalis_application.rb +442 -0
- data/lib/generators/faalis/install_generator.rb +4 -2
- data/lib/generators/faalis/js/list_view_generator.rb +3 -22
- data/lib/generators/faalis/scaffold_generator.rb +7 -10
- data/lib/generators/faalis/templates/README +0 -7
- data/lib/generators/faalis/templates/angularjs/module.js.erb +4 -1
- data/lib/generators/faalis/templates/api/controller.rb.erb +18 -21
- data/lib/generators/faalis/templates/application.js +14 -1
- data/lib/generators/faalis/templates/faalis.rb +3 -1
- data/lib/generators/faalis/templates/i18n/Gruntfile.js.erb +2 -2
- data/lib/generators/faalis/templates/js/list_view/partials/add_controller.js.erb +3 -3
- data/lib/generators/faalis/views_generator.rb +1 -1
- data/lib/tasks/docs.rake +6 -0
- data/lib/tasks/faalis_tasks.rake +1 -0
- data/lib/tasks/grunt/Gruntfile.js +3 -3
- data/spec/dummy/app/controllers/api_controller.rb +5 -0
- data/spec/dummy/config/initializers/faalis.rb +3 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150121060012_create_application_models.model_discovery_engine.rb +10 -0
- data/spec/dummy/db/schema.rb +71 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +544 -0
- data/spec/dummy/log/test.log +12354 -0
- data/spec/factories/faalis/groups.rb +31 -0
- data/spec/factories/faalis/permissions.rb +16 -0
- data/spec/factories/faalis/users.rb +23 -0
- data/spec/models/faalis/group_spec.rb +32 -0
- data/spec/models/faalis/permission_spec.rb +15 -0
- data/spec/models/faalis/user_spec.rb +100 -0
- data/spec/policies/faalis/admin_only_policy_spec.rb +39 -0
- data/spec/policies/faalis/application_policy_spec.rb +49 -0
- data/spec/spec_helper.rb +26 -5
- data/spec/support/factory_girl.rb +3 -0
- metadata +225 -102
- data/app/assets/javascripts/faalis/dashboard/modules/auth/group.js +0 -155
- data/app/assets/javascripts/faalis/dashboard/modules/permissions.js +0 -52
- data/app/controllers/faalis/#api_controller.rb# +0 -51
- data/app/controllers/faalis/#dashboard_controller.rb# +0 -65
- data/app/models/ability.rb +0 -40
- data/app/models/faalis/user/permission.rb +0 -21
- data/app/views/angularjs_templates/modules.html +0 -17
- data/db/migrate/20140617124019_faalis_groups_users.rb +0 -4
- data/lib/faalis/generators/concerns/json_input.rb +0 -41
- data/lib/faalis/generators/fields/#relation.rb# +0 -61
- data/lib/faalis/patches/models.rb +0 -7
@@ -0,0 +1,147 @@
|
|
1
|
+
# This class is one of the most important classes in **Faalis** client side application,
|
2
|
+
# and is responsible for representing a remote resource.
|
3
|
+
class Faalis.Resource
|
4
|
+
|
5
|
+
# Arguments list:
|
6
|
+
# * **options**: Extra properties and attributes to add to the resource.
|
7
|
+
# All the key/value in this object will attached to the
|
8
|
+
# Resource object by transforming key to _<key>. For example
|
9
|
+
# `{ name: "James" } would create an attribute called "_name"
|
10
|
+
# to `Resource` object with value of "James".
|
11
|
+
constructor: (options = {}) ->
|
12
|
+
|
13
|
+
@parents ||= []
|
14
|
+
@_parents_values_is_set = false
|
15
|
+
|
16
|
+
# Put all the options key resource itself
|
17
|
+
Object.keys(options, (key) ->
|
18
|
+
this['_' + key] = options[key]
|
19
|
+
)
|
20
|
+
|
21
|
+
|
22
|
+
type = this._api_type || 'json'
|
23
|
+
api_prefix = this._api_prefix || '/api/v1/'
|
24
|
+
@API = new Faalis.APIFactory(this, type, api_prefix)
|
25
|
+
|
26
|
+
@initialize.$inject = ['$http', '$log', 'catch_error']
|
27
|
+
|
28
|
+
# Set the specific parents of current resource. This method should be called
|
29
|
+
# in controllers and before any use of `Resource` object. and the **parents**
|
30
|
+
# argument should be a object of parent resource name as keys and their id
|
31
|
+
# as value. For example: {'posts': 4 } for 'Comment' Resource.
|
32
|
+
__set_parents__: (parents) ->
|
33
|
+
tmp = []
|
34
|
+
|
35
|
+
for parent in parents
|
36
|
+
tmp.push(parent)
|
37
|
+
tmp.push(parents[parent])
|
38
|
+
|
39
|
+
@parents = tmp
|
40
|
+
|
41
|
+
# This flag will specify the existance of parents
|
42
|
+
@_parents_values_is_set = true
|
43
|
+
|
44
|
+
# Init the resource object to be used in **run** stage. this
|
45
|
+
# method will call by **ResourceFactory** service.
|
46
|
+
__init__: ($http, $log, catch_error) ->
|
47
|
+
|
48
|
+
deps = window.STATIC_REQUIREMENTS.concat(window.dashboard_dependencies)
|
49
|
+
$injector = angular.injector(['ng', 'Errors', 'gettext'])
|
50
|
+
|
51
|
+
Faalis.$injector.invoke(@API.__init__, @API)
|
52
|
+
|
53
|
+
for attr in @__attributes__
|
54
|
+
unless attr.__init__?
|
55
|
+
throw "'" + attr + "' does not have '__init__' method."
|
56
|
+
|
57
|
+
# inject services for field classes.
|
58
|
+
Faalis.$injector.invoke(attr.__init__, attr)
|
59
|
+
|
60
|
+
|
61
|
+
# Initialize the resource object. for example fetch parent objects
|
62
|
+
# or relations and such stuff.
|
63
|
+
initialize: (params) ->
|
64
|
+
_parents = {}
|
65
|
+
|
66
|
+
for parent in @parents
|
67
|
+
_parents[parent] = params[parent + "_id"]
|
68
|
+
|
69
|
+
# Set the current parent objects for API usage
|
70
|
+
@__set_parents__(_parents)
|
71
|
+
|
72
|
+
# Join the given urls and return a uri
|
73
|
+
__join_url__: (url1, urls...) ->
|
74
|
+
'/' + url1.split('/').filter(Boolean).concat(urls).join('/')
|
75
|
+
|
76
|
+
# Parse the given uri and return an object containing the
|
77
|
+
# details
|
78
|
+
__parse_path__: (path) ->
|
79
|
+
parents = []
|
80
|
+
params = [];
|
81
|
+
|
82
|
+
for part in path.split("/")
|
83
|
+
if part.startsWith(':')
|
84
|
+
params.push(part.split(":").last)
|
85
|
+
else
|
86
|
+
parents.push(part.singularize()) unless part.isBlank()
|
87
|
+
|
88
|
+
resource = parents.pop()
|
89
|
+
|
90
|
+
return {
|
91
|
+
parents: parents,
|
92
|
+
params: params,
|
93
|
+
resource: resource
|
94
|
+
}
|
95
|
+
|
96
|
+
# Return the url of current `Resource`
|
97
|
+
to_path: (params...) ->
|
98
|
+
if @_parents_values_is_set == false
|
99
|
+
throw 'You need to set parents values to continue.'
|
100
|
+
|
101
|
+
_parents = @parents[0..]
|
102
|
+
|
103
|
+
for item in params
|
104
|
+
_parents.push(item)
|
105
|
+
|
106
|
+
return '/' + _parents.filter(Boolean).join('/') + @plural_name()
|
107
|
+
|
108
|
+
plural_name: ->
|
109
|
+
@__name__.pluralize()
|
110
|
+
|
111
|
+
# Return the path of template that should be used as the
|
112
|
+
# details template in the final view.
|
113
|
+
__detail_template__: ->
|
114
|
+
# `@_details_template` can be assigned via `ResourceFactory` contructor of
|
115
|
+
# by assigning a value to it after initialization of object.
|
116
|
+
if @_detail_template?
|
117
|
+
return @_detail_template
|
118
|
+
|
119
|
+
else
|
120
|
+
return @plural_name() + "/details"
|
121
|
+
|
122
|
+
|
123
|
+
# API Interface ----------------------------------------------------------
|
124
|
+
# We can use these methods to interact with resource API interface
|
125
|
+
# but the most important thing is to **initialize** the resource
|
126
|
+
# before using these. **ResourceFactory** service will do it
|
127
|
+
# before handing service to the controller or host code.
|
128
|
+
|
129
|
+
# Get a resource instance with given ID
|
130
|
+
find: (id) ->
|
131
|
+
return @API.get(id)
|
132
|
+
|
133
|
+
# Get all the resources via API.
|
134
|
+
all: ->
|
135
|
+
return @API.all()
|
136
|
+
|
137
|
+
# Create a new resource using given **data**
|
138
|
+
create: (data) ->
|
139
|
+
return @API.create(data)
|
140
|
+
|
141
|
+
# Update the resource with given ID using **data** which is provided
|
142
|
+
update: (id, data) ->
|
143
|
+
return @API.update(id, data)
|
144
|
+
|
145
|
+
# Destroy the resource with given id
|
146
|
+
destroy: (id) ->
|
147
|
+
return @API.destroy(id)
|
@@ -1,11 +1,13 @@
|
|
1
|
-
var Auth = angular.module("Auth", ["User","Group"]);
|
1
|
+
var Auth = angular.module("Auth", ["User","Group", "ui.router"]);
|
2
2
|
|
3
|
-
Auth.config(["$
|
3
|
+
/*Auth.config(["$stateProvider", function($stateProvider){
|
4
4
|
$routeProvider.
|
5
|
-
|
5
|
+
state("auth", {
|
6
|
+
url: "/auth",
|
6
7
|
templateUrl: template("auth/index")
|
7
8
|
});
|
8
9
|
}]);
|
10
|
+
*/
|
9
11
|
|
10
12
|
Auth.controller("AuthMenuController", ["$scope", "gettext", function($scope, gettext){
|
11
13
|
this.menu_items = [
|
@@ -1,9 +1,10 @@
|
|
1
|
-
var Profile = angular.module("Profile", []);
|
1
|
+
var Profile = angular.module("Profile", ["ui.router"]);
|
2
2
|
|
3
|
-
Profile.config(["$
|
3
|
+
Profile.config(["$stateProvider", function($stateProvider){
|
4
4
|
|
5
|
-
$
|
6
|
-
|
5
|
+
$stateProvider.
|
6
|
+
state("profile",{
|
7
|
+
url: "/auth/profile/edit",
|
7
8
|
templateUrl: template("auth/profile/edit"),
|
8
9
|
controller: "ProfileController"
|
9
10
|
});
|
@@ -11,7 +12,7 @@ Profile.config(["$routeProvider", function($routeProvider){
|
|
11
12
|
|
12
13
|
|
13
14
|
|
14
|
-
Profile.controller("ProfileController", ["$scope","Restangular","$location" ,"$
|
15
|
+
Profile.controller("ProfileController", ["$scope","Restangular","$location" ,"$stateParams", "gettext", "catch_error", function($scope, API, $location , $stateParams, gettext, catch_error){
|
15
16
|
var obj = API.one("profile").get()
|
16
17
|
.then(function(data){
|
17
18
|
$scope.first_name = data.first_name;
|
@@ -1,17 +1,19 @@
|
|
1
|
-
var User = angular.module("User", ["ListView", "Errors"]);
|
1
|
+
var User = angular.module("User", ["ListView", "Errors", "ui.router"]);
|
2
2
|
|
3
|
-
User.config(["$
|
3
|
+
User.config(["$stateProvider", function($stateProvider){
|
4
4
|
|
5
|
-
$
|
6
|
-
|
5
|
+
$stateProvider.
|
6
|
+
state("users", {
|
7
|
+
url: "/auth/users",
|
7
8
|
templateUrl: template("auth/users/index"),
|
8
9
|
controller: "UsersController"
|
9
10
|
}).
|
10
|
-
|
11
|
+
state("users.new",{
|
12
|
+
url: "/auth/users/new",
|
11
13
|
templateUrl: template("auth/users/new"),
|
12
14
|
controller: "AddUsersController"
|
13
15
|
}).
|
14
|
-
|
16
|
+
state("/auth/users/:id/edit",{
|
15
17
|
templateUrl: template("auth/users/new"),
|
16
18
|
controller: "AddUsersController"
|
17
19
|
});
|
@@ -31,7 +33,7 @@ User.controller("UsersController", ["$scope", "Restangular","gettext", "catch_er
|
|
31
33
|
title: gettext("New"),
|
32
34
|
icon: "fa fa-plus",
|
33
35
|
classes: "btn tiny green",
|
34
|
-
|
36
|
+
state: "#/auth/users/new"
|
35
37
|
}
|
36
38
|
];
|
37
39
|
|
@@ -58,7 +60,7 @@ User.controller("UsersController", ["$scope", "Restangular","gettext", "catch_er
|
|
58
60
|
}]);
|
59
61
|
|
60
62
|
|
61
|
-
User.controller("AddUsersController", ["$scope","Restangular","$location" ,"$
|
63
|
+
User.controller("AddUsersController", ["$scope","Restangular","$location" ,"$stateParams", "gettext", "catch_error", function($scope, API, $location , $stateParams, gettext, catch_error){
|
62
64
|
|
63
65
|
API.all("groups").getList().then(
|
64
66
|
function(data){
|
@@ -66,8 +68,8 @@ User.controller("AddUsersController", ["$scope","Restangular","$location" ,"$rou
|
|
66
68
|
});
|
67
69
|
|
68
70
|
$scope.obj_id = null;
|
69
|
-
if("id" in $
|
70
|
-
$scope.obj_id = $
|
71
|
+
if("id" in $stateParams){
|
72
|
+
$scope.obj_id = $stateParams.id;
|
71
73
|
var obj = API.one("users", $scope.obj_id).get()
|
72
74
|
.then(function(data){
|
73
75
|
$scope.first_name = data.first_name;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
var Conversation = angular.module("Conversation",["ListView", "Errors"]);
|
1
|
+
/*var Conversation = angular.module("Conversation",["ListView", "Errors"]);
|
2
2
|
|
3
3
|
|
4
4
|
Conversation.config(["$routeProvider", function($routeProvider){
|
@@ -179,3 +179,4 @@ Conversation.controller("ConversationControllerNew", ["$scope", "Restangular", "
|
|
179
179
|
|
180
180
|
|
181
181
|
}]);
|
182
|
+
*/
|
@@ -0,0 +1,43 @@
|
|
1
|
+
var Image_ = angular.module("ImageField",[]);
|
2
|
+
|
3
|
+
/*
|
4
|
+
* <image-field></image-field>
|
5
|
+
*/
|
6
|
+
|
7
|
+
Image_.directive('imageField',["gettext", "$parse", function(gettext, $parse){
|
8
|
+
function link(scope, element, attrs, ngctrl){
|
9
|
+
console.group("ImageField");
|
10
|
+
scope.element_id = "id_" + scope.field;
|
11
|
+
scope.msg_element_id = "id_" + scope.field + "_msg";
|
12
|
+
|
13
|
+
function updateModel(event){
|
14
|
+
if(event.target && event.target.files){
|
15
|
+
var file = event.target.files[0];
|
16
|
+
var reader = new FileReader();
|
17
|
+
reader.onload = function(e){
|
18
|
+
var image = e.target.result;
|
19
|
+
console.log("IMAGE DATA: %s", image);
|
20
|
+
ngctrl.$setViewValue({filename: file.name,
|
21
|
+
image_data: image,
|
22
|
+
content_type: file.type});
|
23
|
+
ngctrl.$render();
|
24
|
+
|
25
|
+
};
|
26
|
+
reader.readAsDataURL(file);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
element.on('change',updateModel);
|
31
|
+
console.groupEnd();
|
32
|
+
}
|
33
|
+
return {
|
34
|
+
templateUrl: template("fields/image/image"),
|
35
|
+
//getting deprecated
|
36
|
+
//replace: true,
|
37
|
+
restrict: "E",
|
38
|
+
require: 'ngModel', // get a hold of NgModelController
|
39
|
+
//transclude: true,
|
40
|
+
link: link
|
41
|
+
};
|
42
|
+
|
43
|
+
}]);
|
@@ -0,0 +1,51 @@
|
|
1
|
+
var Date_ = angular.module("DateField", []);
|
2
|
+
|
3
|
+
/*
|
4
|
+
* <string-field></string-field> directive defination
|
5
|
+
*/
|
6
|
+
|
7
|
+
Date_.directive('dateField', ["$filter", "gettext", function($filter, gettext) {
|
8
|
+
|
9
|
+
function link(scope, element, attrs){
|
10
|
+
var ltr = is_ltr();
|
11
|
+
var locale = (ltr) ? 'en' : 'fa';
|
12
|
+
scope.element_id = "id_" + scope.field;
|
13
|
+
element.find('div.date').datetimepicker({
|
14
|
+
icons:{
|
15
|
+
time: 'fa fa-clock-o',
|
16
|
+
date: 'fa fa-calendar',
|
17
|
+
up: 'fa fa-chevron-up',
|
18
|
+
down: 'fa fa-chevron-down',
|
19
|
+
previous: 'fa fa-chevron-left',
|
20
|
+
next: 'fa fa-chevron-right',
|
21
|
+
today: 'fa fa-screenshot',
|
22
|
+
clear: 'fa fa-trash'
|
23
|
+
},
|
24
|
+
format: 'dd-MM-yy',
|
25
|
+
locale: locale
|
26
|
+
|
27
|
+
});
|
28
|
+
}
|
29
|
+
// Actual object of <date-field> directive
|
30
|
+
return {
|
31
|
+
templateUrl: template("fields/datetime/date"),
|
32
|
+
replace: true,
|
33
|
+
restrict: "E",
|
34
|
+
transclude: true,
|
35
|
+
scope: {
|
36
|
+
// disable timepicker
|
37
|
+
timepicker: "=?",
|
38
|
+
|
39
|
+
cssClasses: '=cssClass',
|
40
|
+
// A call back to pass to field ng-change directive
|
41
|
+
on_change: "@onChange",
|
42
|
+
// fieldname
|
43
|
+
field: "=fieldName",
|
44
|
+
// Does this field is required
|
45
|
+
required: "=",
|
46
|
+
// Actual Angularjs ng-model
|
47
|
+
model: '='
|
48
|
+
},
|
49
|
+
link: link
|
50
|
+
};
|
51
|
+
}]);
|
@@ -1,29 +1,40 @@
|
|
1
|
-
var Datetime_ = angular.module("DatetimeField", [
|
1
|
+
var Datetime_ = angular.module("DatetimeField", []);
|
2
2
|
|
3
3
|
/*
|
4
4
|
* <string-field></string-field> directive defination
|
5
5
|
*/
|
6
6
|
|
7
|
-
Datetime_.directive('datetimeField', ["$filter", "gettext",
|
7
|
+
Datetime_.directive('datetimeField', ["$filter", "gettext", function($filter, gettext) {
|
8
8
|
|
9
9
|
function link(scope, element, attrs){
|
10
10
|
var ltr = is_ltr();
|
11
|
+
var locale = (ltr) ? 'en' : 'fa';
|
11
12
|
scope.element_id = "id_" + scope.field;
|
12
|
-
|
13
|
+
//TODO: change the find selector to use ID
|
14
|
+
element.find('div.date').datetimepicker({
|
15
|
+
icons:{
|
16
|
+
time: 'fa fa-clock-o',
|
17
|
+
date: 'fa fa-calendar',
|
18
|
+
up: 'fa fa-chevron-up',
|
19
|
+
down: 'fa fa-chevron-down',
|
20
|
+
previous: 'fa fa-chevron-left',
|
21
|
+
next: 'fa fa-chevron-right',
|
22
|
+
today: 'fa fa-screenshot',
|
23
|
+
clear: 'fa fa-trash'
|
24
|
+
},
|
25
|
+
widgetPositioning: {
|
26
|
+
horizontal: 'left',
|
27
|
+
vertical: 'bottom'
|
28
|
+
},
|
29
|
+
sideBySide: true,
|
30
|
+
locale: locale
|
13
31
|
|
14
|
-
|
15
|
-
scope.timepicker = true;
|
16
|
-
}
|
17
|
-
console.log(scope);
|
18
|
-
console.log(scope.timepicker);
|
19
|
-
if (scope.on_change !== undefined) {
|
20
|
-
// Watch event changes
|
21
|
-
scope.$watch("model", function(newv, oldv, $scope) {
|
22
|
-
// TODO: maybe we should pass locals to $eval
|
23
|
-
scope.$parent.$eval(scope.on_change);
|
24
|
-
}, true);
|
25
|
-
}
|
32
|
+
});
|
26
33
|
|
34
|
+
scope.$watch('fake_model', function(x, y) {
|
35
|
+
console.log('---------------');
|
36
|
+
console.log("%s -- %s", x , y);
|
37
|
+
});
|
27
38
|
}
|
28
39
|
// Actual object of <datetime-field> directive
|
29
40
|
return {
|
@@ -1 +1,3 @@
|
|
1
|
-
angular.module("Fields", ["RelationField", "StringField", "IntegerField", "TextField",
|
1
|
+
angular.module("Fields", ["RelationField", "StringField", "IntegerField", "TextField",
|
2
|
+
"BooleanField", "DatetimeField", "TimeField","DateField" ,
|
3
|
+
"FloatField", "ImageField", "TagField", "FileField"]);
|
@@ -0,0 +1,43 @@
|
|
1
|
+
var File_ = angular.module("FileField",[]);
|
2
|
+
|
3
|
+
/*
|
4
|
+
* <file-field></file-field>
|
5
|
+
*/
|
6
|
+
|
7
|
+
File_.directive('fileField',["gettext", "$parse", function(gettext, $parse){
|
8
|
+
function link(scope, element, attrs, ngctrl){
|
9
|
+
console.group("FileField");
|
10
|
+
scope.element_id = "id_" + scope.field;
|
11
|
+
scope.msg_element_id = "id_" + scope.field + "_msg";
|
12
|
+
|
13
|
+
function updateModel(event){
|
14
|
+
if(event.target && event.target.files){
|
15
|
+
var file = event.target.files[0];
|
16
|
+
var reader = new FileReader();
|
17
|
+
reader.onload = function(e){
|
18
|
+
var data_ = e.target.result;
|
19
|
+
console.log("FILE DATA: %s", data_);
|
20
|
+
ngctrl.$setViewValue({filename: file.name,
|
21
|
+
data: data_,
|
22
|
+
content_type: file.type});
|
23
|
+
ngctrl.$render();
|
24
|
+
|
25
|
+
};
|
26
|
+
reader.readAsDataURL(file);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
element.on('change',updateModel);
|
31
|
+
console.groupEnd();
|
32
|
+
}
|
33
|
+
return {
|
34
|
+
templateUrl: template_url("fields/file/file_upload"),
|
35
|
+
//getting deprecated
|
36
|
+
//replace: true,
|
37
|
+
restrict: "E",
|
38
|
+
require: 'ngModel', // get a hold of NgModelController
|
39
|
+
//transclude: true,
|
40
|
+
link: link
|
41
|
+
};
|
42
|
+
|
43
|
+
}]);
|