Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

making 2 javascript partial templates for the permissions management,…

… adding options for jquery and prototype
  • Loading branch information...
commit e264e790d806a89c0e18dedc9028ccd544a6c921 1 parent 55012d3
Daniel authored
3  devisable.gemspec
View
@@ -68,7 +68,8 @@ Gem::Specification.new do |s|
"lib/generators/devisable/templates/partials/_migration_up.rb",
"lib/generators/devisable/templates/partials/_oauth_user_table_fields.erb",
"lib/generators/devisable/templates/partials/_permission_equals.rb",
- "lib/generators/devisable/templates/partials/_permission_manage.js",
+ "lib/generators/devisable/templates/partials/_permission_manage_prototype.js",
+ "lib/generators/devisable/templates/partials/_permission_manage_jquery.js",
"lib/generators/devisable/templates/partials/_role_permission.rb",
"lib/generators/devisable/templates/partials/_roles_index_delete.erb",
"lib/generators/devisable/templates/partials/_user_model_methods.erb",
11 lib/generators/devisable/devisable_generator.rb
View
@@ -91,6 +91,13 @@ def initialize(*runtime_args)
opts.on("-C", "--cucumber [string]", String, "Include cucumber tests") do |v|
@@actual_configuration_options['cucumber'] = true
end
+ opts.on("-j", "--jslibrary (jquery|prototype)", String, "write out using the jquery or prototype libraries") do |j|
+ if j =~ /jquery/i
+ @@actual_configuration_options['jslibrary'] = 'jquery'
+ else if j =~ /prototype/i
+ @@actual_configuration_options['jslibrary'] = 'prototype'
+ end
+ end
end.parse!
execute
end
@@ -100,7 +107,7 @@ def initialize(*runtime_args)
def throw_error(error = '')
puts error
exit();
- end
+ end
#replaces the last string 'end' in a file with the value of rep_str
#
@@ -400,7 +407,7 @@ def new_project
#adds the javascript for the role permissions checkboxes
def add_javascript
- rep_str = load_erb_string('partials/_permission_manage.js')
+ rep_str = load_erb_string('partials/_permission_manage_' + @@actual_configuration_options['jslibrary'] + '.js')
append_to_file "public/javascripts/application.js", rep_str
end
18 lib/generators/devisable/templates/partials/_permission_manage.js
View
@@ -1,18 +0,0 @@
-document.observe("dom:loaded", function() {
- $$('.permission_manage').each(function(pm) {
- pm.observe('click', function(event) {
- use_permission_clicked(event.element())
- });
- use_permission_clicked(pm)
- });
-
- function use_permission_clicked(obj) {
- var controller = obj.id.split('_')[1]
- var disabled_val = obj.checked ? 'disabled' : false;
- $('permission_' + controller + '_read').disabled = disabled_val;
- $('permission_' + controller + '_create').disabled = disabled_val;
- $('permission_' + controller + '_update').disabled = disabled_val;
- $('permission_' + controller + '_destroy').disabled = disabled_val;
- }
-});
-
21 lib/generators/devisable/templates/partials/_permission_manage_jquery.js
View
@@ -0,0 +1,21 @@
+/*
+ * Devisable -- Permissions Edit-Add Form
+ * route: /roles/:id/edit
+ */
+(function() {
+ function use_permission_clicked(obj) {
+ var controller = $(obj).attr('id').split('_')[1]
+ var disabled_val = $(obj).is(':checked');
+ $('#permission_' + controller + '_read').attr('disabled',disabled_val);
+ $('#permission_' + controller + '_create').attr('disabled',disabled_val);
+ $('#permission_' + controller + '_update').attr('disabled',disabled_val);
+ $('#permission_' + controller + '_destroy').attr('disabled',disabled_val);
+ }
+
+ $('.permission_manage').each(function(ind,pm) {
+ $('.permission_manage').click(function() {
+ use_permission_clicked($(this));
+ });
+ use_permission_clicked(pm)
+ });
+)
22 lib/generators/devisable/templates/partials/_permission_manage_prototype.js
View
@@ -0,0 +1,22 @@
+/*
+ * Devisable -- Permissions Edit-Add Form
+ * route: /roles/:id/edit
+ */
+document.observe("dom:loaded", function() {
+ $$('.permission_manage').each(function(pm) {
+ pm.observe('click', function(event) {
+ use_permission_clicked(event.element())
+ });
+ use_permission_clicked(pm)
+ });
+
+ function use_permission_clicked(obj) {
+ var controller = obj.id.split('_')[1]
+ var disabled_val = obj.checked ? 'disabled' : false;
+ $('permission_' + controller + '_read').disabled = disabled_val;
+ $('permission_' + controller + '_create').disabled = disabled_val;
+ $('permission_' + controller + '_update').disabled = disabled_val;
+ $('permission_' + controller + '_destroy').disabled = disabled_val;
+ }
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.