Skip to content
This repository

These are good commits! #3

Merged
merged 2 commits into from over 2 years ago

2 participants

Daniel scottsampson
Daniel

And I like your software!

scottsampson scottsampson merged commit 9d8b091 into from August 18, 2011
scottsampson scottsampson closed this August 18, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Aug 18, 2011
Daniel making 2 javascript partial templates for the permissions management,…
… adding options for jquery and prototype
e264e79
Daniel working! 9fc5442
This page is out of date. Refresh to see the latest.
3  devisable.gemspec
@@ -68,7 +68,8 @@ Gem::Specification.new do |s|
68 68
     "lib/generators/devisable/templates/partials/_migration_up.rb",
69 69
     "lib/generators/devisable/templates/partials/_oauth_user_table_fields.erb",
70 70
     "lib/generators/devisable/templates/partials/_permission_equals.rb",
71  
-    "lib/generators/devisable/templates/partials/_permission_manage.js",
  71
+    "lib/generators/devisable/templates/partials/_permission_manage_prototype.js",
  72
+    "lib/generators/devisable/templates/partials/_permission_manage_jquery.js",
72 73
     "lib/generators/devisable/templates/partials/_role_permission.rb",
73 74
     "lib/generators/devisable/templates/partials/_roles_index_delete.erb",
74 75
     "lib/generators/devisable/templates/partials/_user_model_methods.erb",
14  lib/generators/devisable/devisable_generator.rb
@@ -29,7 +29,8 @@ class DevisableGenerator < Rails::Generators::Base
29 29
     'extra' => [],
30 30
     'new' => false,
31 31
     'sudo' => false,
32  
-    'url' => 'http://localhost:3000'
  32
+    'url' => 'http://localhost:3000',
  33
+    'jslibrary' => ''
33 34
   }
34 35
   
35 36
   
@@ -91,6 +92,13 @@ def initialize(*runtime_args)
91 92
       opts.on("-C", "--cucumber [string]", String, "Include cucumber tests") do |v|
92 93
         @@actual_configuration_options['cucumber'] = true
93 94
       end
  95
+      opts.on("-j", "--jslibrary (jquery|prototype)", String, "write out using the jquery or prototype libraries") do |j|
  96
+        if j =~ /jquery/i
  97
+          @@actual_configuration_options['jslibrary'] = 'jquery'
  98
+        elsif j =~ /prototype/i
  99
+          @@actual_configuration_options['jslibrary'] = 'prototype'
  100
+        end
  101
+      end
94 102
     end.parse!
95 103
     execute
96 104
   end
@@ -100,7 +108,7 @@ def initialize(*runtime_args)
100 108
   def throw_error(error = '')
101 109
     puts error
102 110
     exit();
103  
-  end  
  111
+  end
104 112
   
105 113
   #replaces the last string 'end' in a file with the value of rep_str
106 114
   #
@@ -400,7 +408,7 @@ def new_project
400 408
   
401 409
   #adds the javascript for the role permissions checkboxes
402 410
   def add_javascript
403  
-    rep_str = load_erb_string('partials/_permission_manage.js')
  411
+    rep_str = load_erb_string('partials/_permission_manage_' + @@actual_configuration_options['jslibrary'] + '.js')
404 412
     append_to_file "public/javascripts/application.js", rep_str
405 413
   end
406 414
 
18  lib/generators/devisable/templates/partials/_permission_manage.js
... ...
@@ -1,18 +0,0 @@
1  
-document.observe("dom:loaded", function() {
2  
-  $$('.permission_manage').each(function(pm) {
3  
-    pm.observe('click', function(event) {  
4  
-      use_permission_clicked(event.element())
5  
-    });
6  
-    use_permission_clicked(pm)
7  
-  });
8  
-
9  
-  function use_permission_clicked(obj) {
10  
-    var controller = obj.id.split('_')[1]
11  
-    var disabled_val = obj.checked ? 'disabled' : false;
12  
-    $('permission_' + controller + '_read').disabled = disabled_val;
13  
-    $('permission_' + controller + '_create').disabled = disabled_val;
14  
-    $('permission_' + controller + '_update').disabled = disabled_val;
15  
-    $('permission_' + controller + '_destroy').disabled = disabled_val;
16  
-  }
17  
-});
18  
-
21  lib/generators/devisable/templates/partials/_permission_manage_jquery.js
... ...
@@ -0,0 +1,21 @@
  1
+/* 
  2
+ *  Devisable -- Permissions Edit-Add Form
  3
+ *  route: /roles/:id/edit
  4
+ */
  5
+$(document).ready(function() {
  6
+ function use_permission_clicked(obj) {
  7
+  var controller = $(obj).attr('id').split('_')[1]
  8
+  var disabled_val = $(obj).is(':checked')
  9
+  $('#permission_' + controller + '_read').attr('disabled',disabled_val)
  10
+  $('#permission_' + controller + '_create').attr('disabled',disabled_val)
  11
+  $('#permission_' + controller + '_update').attr('disabled',disabled_val)
  12
+  $('#permission_' + controller + '_destroy').attr('disabled',disabled_val)
  13
+ }
  14
+ 
  15
+ $('.permission_manage').each(function(ind,pm) {
  16
+  $('.permission_manage').click(function() {
  17
+   use_permission_clicked($(this))
  18
+  }) 
  19
+  use_permission_clicked(pm)
  20
+ })
  21
+})
22  lib/generators/devisable/templates/partials/_permission_manage_prototype.js
... ...
@@ -0,0 +1,22 @@
  1
+/* 
  2
+ *  Devisable -- Permissions Edit-Add Form
  3
+ *  route: /roles/:id/edit
  4
+ */
  5
+document.observe("dom:loaded", function() {
  6
+ $$('.permission_manage').each(function(pm) {
  7
+  pm.observe('click', function(event) {  
  8
+   use_permission_clicked(event.element())
  9
+  });
  10
+  use_permission_clicked(pm)
  11
+ });
  12
+
  13
+ function use_permission_clicked(obj) {
  14
+  var controller = obj.id.split('_')[1]
  15
+  var disabled_val = obj.checked ? 'disabled' : false;
  16
+  $('permission_' + controller + '_read').disabled = disabled_val;
  17
+  $('permission_' + controller + '_create').disabled = disabled_val;
  18
+  $('permission_' + controller + '_update').disabled = disabled_val;
  19
+  $('permission_' + controller + '_destroy').disabled = disabled_val;
  20
+ }
  21
+});
  22
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.