aslon_scaffold 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README +26 -0
- data/Rakefile +2 -0
- data/aslon_scaffold.gemspec +33 -0
- data/config/locales/aslon_scaffold.fr.yml +14 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/app/controllers/articles_controller.rb +7 -0
- data/lib/app/helpers/application_helper.rb +410 -0
- data/lib/app/views/aslon_scaffolds/_search.haml +1 -0
- data/lib/app/views/aslon_scaffolds/index.haml +4 -0
- data/lib/app/views/aslon_scaffolds/new_edit.haml +8 -0
- data/lib/app/views/aslon_scaffolds/show.haml +9 -0
- data/lib/aslon_scaffold.rb +34 -0
- data/lib/aslon_scaffold/aslon_scaffold.rb +237 -0
- data/lib/aslon_scaffold/version.rb +4 -0
- data/lib/generators/haml.rb +11 -0
- data/lib/generators/haml/scaffold/scaffold_generator.rb +25 -0
- data/lib/generators/haml/scaffold/templates/_new_edit.haml.erb +6 -0
- data/lib/generators/haml/scaffold/templates/_search.haml.erb +6 -0
- data/lib/generators/haml/scaffold/templates/edit.haml.erb +5 -0
- data/lib/generators/haml/scaffold/templates/index.haml.erb +10 -0
- data/lib/generators/haml/scaffold/templates/layout.haml.erb +17 -0
- data/lib/generators/haml/scaffold/templates/new.haml.erb +6 -0
- data/lib/generators/haml/scaffold/templates/new_edit.haml.erb +13 -0
- data/lib/generators/haml/scaffold/templates/show.haml.erb +14 -0
- data/lib/generators/nifty.rb +28 -0
- data/lib/generators/nifty/aslon/USAGE +51 -0
- data/lib/generators/nifty/aslon/aslon_generator.rb +320 -0
- data/lib/generators/nifty/aslon/templates/actions/create.rb +8 -0
- data/lib/generators/nifty/aslon/templates/actions/destroy.rb +5 -0
- data/lib/generators/nifty/aslon/templates/actions/edit.rb +3 -0
- data/lib/generators/nifty/aslon/templates/actions/index.rb +3 -0
- data/lib/generators/nifty/aslon/templates/actions/new.rb +3 -0
- data/lib/generators/nifty/aslon/templates/actions/show.rb +3 -0
- data/lib/generators/nifty/aslon/templates/actions/update.rb +8 -0
- data/lib/generators/nifty/aslon/templates/controller.rb +10 -0
- data/lib/generators/nifty/aslon/templates/fixtures.yml +9 -0
- data/lib/generators/nifty/aslon/templates/helper.rb +2 -0
- data/lib/generators/nifty/aslon/templates/migration.rb +16 -0
- data/lib/generators/nifty/aslon/templates/model.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/nifty/aslon/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/nifty/aslon/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/nifty/aslon/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/nifty/aslon/templates/views/haml/_new_edit.html.haml +6 -0
- data/lib/generators/nifty/aslon/templates/views/haml/_search.html.haml +6 -0
- data/lib/generators/nifty/aslon/templates/views/haml/index.html.haml +10 -0
- data/lib/generators/nifty/aslon/templates/views/haml/layout.haml.erb +17 -0
- data/lib/generators/nifty/aslon/templates/views/haml/new_edit.html.haml +13 -0
- data/lib/generators/nifty/aslon/templates/views/haml/show.html.haml +14 -0
- data/lib/generators/nifty/layout/USAGE +25 -0
- data/lib/generators/nifty/layout/layout_generator.rb +42 -0
- data/lib/generators/nifty/layout/templates/_default.html.haml +9 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/add.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/delete.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/edit.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/folder.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/grid-blue-hd.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/grid-split.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/grid3-hrow.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/indicator.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/magnifier.png +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/sort_asc.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/images/aslon_scaffold/sort_desc.gif +0 -0
- data/lib/generators/nifty/layout/templates/assets/stylesheets/aslon_scaffold/base.css.sass +263 -0
- data/lib/generators/nifty/layout/templates/assets/stylesheets/aslon_scaffold/formtastic.css.sass +176 -0
- data/lib/generators/nifty/layout/templates/assets/stylesheets/aslon_scaffold/formtastic_changes.css.sass +31 -0
- data/lib/generators/nifty/layout/templates/assets/stylesheets/aslon_scaffold/table_coffee_with_milk.css.sass +94 -0
- data/lib/generators/nifty/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/nifty/layout/templates/layout.html.haml +13 -0
- data/lib/generators/nifty/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/nifty/layout/templates/locales/aslon_scaffold.fr.yml +14 -0
- data/lib/generators/nifty/scaffold/USAGE +51 -0
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +319 -0
- data/lib/generators/nifty/scaffold/templates/actions/create.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/actions/destroy.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/update.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/controller.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/fixtures.yml +9 -0
- data/lib/generators/nifty/scaffold/templates/helper.rb +2 -0
- data/lib/generators/nifty/scaffold/templates/migration.rb +16 -0
- data/lib/generators/nifty/scaffold/templates/model.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/_form.html.erb +10 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/show.html.erb +20 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/_new_edit.html.haml +6 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/_search.html.haml +6 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/index.html.haml +10 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/layout.haml.erb +17 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/new_edit.haml.erb +13 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/show.haml.erb +14 -0
- data/lib/generators/templates/rails/scaffold_controller/controller.rb +11 -0
- data/lib/tasks/aslon_scaffold_tasks.rake +91 -0
- data/lib/tasks/task.rake +113 -0
- data/test/articles_controller_test.rb +24 -0
- data/test/database.yml +8 -0
- data/test/schema.rb +6 -0
- data/test/test_helper.rb +39 -0
- data/test/undeletable_plugin.sqlite.db +0 -0
- data/test/undeletable_plugin2.sqlite3.db +0 -0
- data/uninstall.rb +1 -0
- data/vendor/assets/images/aslon_scaffold/add.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/delete.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/edit.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/folder.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/grid-blue-hd.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/grid-split.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/grid3-hrow.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/indicator.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/magnifier.png +0 -0
- data/vendor/assets/images/aslon_scaffold/sort_asc.gif +0 -0
- data/vendor/assets/images/aslon_scaffold/sort_desc.gif +0 -0
- data/vendor/assets/stylesheets/aslon_scaffold_base.css.sass +116 -0
- data/vendor/assets/stylesheets/aslon_scaffold_base.css.sass.old +263 -0
- data/vendor/assets/stylesheets/aslon_scaffold_table.css.sass +94 -0
- data/vendor/assets/stylesheets/formtastic_changes.css.sass +31 -0
- metadata +185 -4
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Aslon Scaffold
|
2
|
+
===========
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
Example
|
7
|
+
=======
|
8
|
+
|
9
|
+
class LanguesController < ApplicationController
|
10
|
+
aslon_scaffold
|
11
|
+
end
|
12
|
+
|
13
|
+
class LanguesController < ApplicationController
|
14
|
+
aslon_scaffold :display_columns=>%w(lib code)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class LanguesController < ApplicationController
|
19
|
+
aslon_scaffold :display_columns=>%w(lib code),
|
20
|
+
:show_fields=>%w(lib code id),
|
21
|
+
:edit_fields=%w(lib)
|
22
|
+
:search_fields=>%w(lib),
|
23
|
+
:legend=>"Hello"
|
24
|
+
end
|
25
|
+
|
26
|
+
Copyright (c) 2009 [name of plugin creator], released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "aslon_scaffold/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "aslon_scaffold"
|
8
|
+
s.version = AslonScaffold::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["alson"]
|
11
|
+
s.email = ["Write your email address"]
|
12
|
+
s.homepage = ""
|
13
|
+
s.summary = %q{TOD O: Write a gem summary}
|
14
|
+
s.description = %q{Write a gem description}
|
15
|
+
|
16
|
+
s.rubyforge_project = "aslon_scaff old"
|
17
|
+
|
18
|
+
# s.files = `git ls-files`.split("\n")
|
19
|
+
# s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.files = `git ls-files`.split($/)
|
22
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
23
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
s.add_dependency('will_paginate', '~> 3.0.pre2')
|
27
|
+
s.add_dependency('formtastic', '~>2')
|
28
|
+
s.add_dependency('haml')
|
29
|
+
s.add_dependency('sass')
|
30
|
+
s.add_dependency('dynamic_form')
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
fr:
|
3
|
+
views:
|
4
|
+
generic:
|
5
|
+
edit: "Edition : %{model}"
|
6
|
+
new: "Nouveau : %{model}"
|
7
|
+
index: "Liste : %{model}"
|
8
|
+
messages:
|
9
|
+
ok_created: "%{model} : OK création"
|
10
|
+
ok_deleted: "OK suppression"
|
11
|
+
ko_deleted: "KO suppression"
|
12
|
+
ok_updated: "OK mise à jour"
|
13
|
+
mise_a_jour: "Mise à jour"
|
14
|
+
model: "Modèle"
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'aslon_scaffold'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,410 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Methods added to this helper will be available to all templates in the application.
|
4
|
+
module ApplicationHelper
|
5
|
+
|
6
|
+
def ican?(*args)
|
7
|
+
begin
|
8
|
+
# if CanCan plugin installed
|
9
|
+
can?(*args)
|
10
|
+
rescue
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def icannot?(*args)
|
15
|
+
begin
|
16
|
+
# if CanCan plugin installed
|
17
|
+
cannot?(*args)
|
18
|
+
rescue
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def url(v)
|
24
|
+
if v =~ /http:/
|
25
|
+
return "<a href=#{v}>#{v}</a>"
|
26
|
+
else
|
27
|
+
return v
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def show(objet,attribut)
|
32
|
+
|
33
|
+
|
34
|
+
aslib= eval "#{objet.class.name}.human_attribute_name(attribut)"
|
35
|
+
begin
|
36
|
+
if attribut.split('.').size==2
|
37
|
+
return ("<li class='string input optional stringish'><label class='label'>#{aslib}</label>"+objet.send( attribut.split('.').first).send( attribut.split('.').second).to_s+"</li>").html_safe
|
38
|
+
else
|
39
|
+
return ("<li class='string input optional stringish'><label class='label'>#{aslib}</label>"+url(objet.send(attribut).to_s)+"</li>").html_safe
|
40
|
+
end
|
41
|
+
|
42
|
+
rescue
|
43
|
+
return ("<li class='string input optional stringish'><label class='label'>#{aslib}</label>?</li>").html_safe
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def model_name(model)
|
48
|
+
begin
|
49
|
+
eval("#{model}.model_name.human")
|
50
|
+
rescue
|
51
|
+
model.humanize
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def titre_action (action,model)
|
55
|
+
txt=model_name(model)
|
56
|
+
("<h1 class='aslon_scaffold'>"+t("views.generic.#{action}", :model=>txt)+"</h1>").html_safe
|
57
|
+
end
|
58
|
+
|
59
|
+
def titre_show(objet, lib)
|
60
|
+
model=objet.class
|
61
|
+
begin
|
62
|
+
txt=eval("#{model}.model_name.human")
|
63
|
+
rescue
|
64
|
+
txt= model.model_name
|
65
|
+
end
|
66
|
+
("<h1 class='aslon_scaffold'> #{txt} : #{lib} #{link_to_image_edit(objet)} #{link_to_image_delete(objet)}</h1>").html_safe
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def link_to_image_edit(objet)
|
71
|
+
if ican? :edit,objet
|
72
|
+
link_to image_edit,eval("edit_#{objet.class.to_s.underscore.gsub('/','_')}_path(objet)"),:id=>'edit'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def link_to_image_add(objet)
|
76
|
+
if ican? :create,objet
|
77
|
+
link_to image_add,eval("new_#{objet.class.to_s.underscore}_path(objet)"),:id=>'add'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
def link_to_image_delete(objet)
|
81
|
+
if ican? :destroy, objet
|
82
|
+
link_to(image_delete, objet, :confirm => 'Are you sure?', :method => :delete, :id=>'delete')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
# --------------------------------------------------------------------------------
|
90
|
+
# Création de la barre de titre à associé au tableau
|
91
|
+
# --------------------------------------------------------------------------------
|
92
|
+
def titre(titre, model=nil, search=true, add=true, action='search',addlink=nil)
|
93
|
+
|
94
|
+
s=form_tag('javascript:void(0)' )
|
95
|
+
s="
|
96
|
+
<table id='titreliste' cellpadding='0' cellspacing='0' >
|
97
|
+
<tr>
|
98
|
+
<th COLSPAN='10'>#{titre}"
|
99
|
+
if add==true
|
100
|
+
if addlink==nil
|
101
|
+
t="new_"+model.singularize.underscore.gsub('/','_') + "_path(:fournisseur_id=>params[:fournisseur_id],
|
102
|
+
:rfq_id=>params[:rfq_id],
|
103
|
+
:client_id=>params[:client_id])"
|
104
|
+
else
|
105
|
+
t=addlink
|
106
|
+
end
|
107
|
+
s<<link_to(image_add, eval(t),:id=>'add') if ican?(:create, eval(model.camelcase))
|
108
|
+
|
109
|
+
end
|
110
|
+
if search
|
111
|
+
s<<" "+image_tag("aslon_scaffold/grid-split.gif", :border=>0, :style=>"vertical-align:middle")
|
112
|
+
s<<" Search : "
|
113
|
+
s<< text_field_tag( :search, nil, {:size=>10})
|
114
|
+
s<< image_tag("aslon_scaffold/indicator.gif", :style=>"vertical-align:middle", :border => 0, :id => "spiner",:style => "display:none;" )
|
115
|
+
end
|
116
|
+
s<<"</th>
|
117
|
+
</tr>
|
118
|
+
</table>"
|
119
|
+
if search
|
120
|
+
cond=":type=>'simle'"
|
121
|
+
# s<< observe_field(:search,
|
122
|
+
# :frequency=>1,
|
123
|
+
# :update=>"ajaxw",
|
124
|
+
# :before=>"Element.show('spiner')",
|
125
|
+
# :success=>"Element.hide('spiner')",
|
126
|
+
# :url=>{ :controller=>model.underscore.pluralize,
|
127
|
+
# :action=>action,
|
128
|
+
# :method => 'get',
|
129
|
+
# :only_path=>false,
|
130
|
+
# :type=>params[:type],
|
131
|
+
# :status=>params[:status],
|
132
|
+
# :fournisseur_id=>params[:fournisseur_id],
|
133
|
+
# :rfq_id=>params[:rfq_id],
|
134
|
+
# :client_id=>params[:client_id]
|
135
|
+
# },
|
136
|
+
# :with=>"'search='+encodeURIComponent(value)")
|
137
|
+
url= url_for(:action => 'search', :controller => model.underscore.pluralize)
|
138
|
+
|
139
|
+
s<< "<script>
|
140
|
+
$(document).ready(function(){
|
141
|
+
|
142
|
+
$('#search').bind('keyup', function() {
|
143
|
+
$('#spiner').show();
|
144
|
+
var url = '#{url}';
|
145
|
+
var formData = 'search='+encodeURIComponent($('#search').val());
|
146
|
+
$.post(url, formData, function(html) {
|
147
|
+
$('#spiner').hide(); // hide the spinner
|
148
|
+
$('#ajaxw').html(html);
|
149
|
+
});
|
150
|
+
});
|
151
|
+
|
152
|
+
});
|
153
|
+
</script>"
|
154
|
+
|
155
|
+
end
|
156
|
+
return s.html_safe
|
157
|
+
|
158
|
+
end
|
159
|
+
# --------------------------------------------------------------------------------
|
160
|
+
# Création d'un tableau
|
161
|
+
# --------------------------------------------------------------------------------
|
162
|
+
def table(model, table, h, actions)
|
163
|
+
sel=''
|
164
|
+
sel='&type='+params[:type] if params[:type]
|
165
|
+
sel+='&status='+params[:status] if params[:status]
|
166
|
+
|
167
|
+
wp=will_paginate(table)
|
168
|
+
info_titre_tableau=page_entries_info(table)
|
169
|
+
s=''.force_encoding('utf-8')
|
170
|
+
# --------------------------------------------------------------------
|
171
|
+
s<<"<table id='liste'>
|
172
|
+
<caption>#{info_titre_tableau}</caption>
|
173
|
+
<thead>
|
174
|
+
<tr>"
|
175
|
+
# --------------------------------------------------------------------
|
176
|
+
# intitulé des colonnes
|
177
|
+
# --------------------------------------------------------------------
|
178
|
+
|
179
|
+
h.each do |value|
|
180
|
+
img='aslon_scaffold/sort_desc.gif'
|
181
|
+
sens='DESC'
|
182
|
+
if params[:order]==value && params[:sens]=='DESC'
|
183
|
+
sens='ASC'
|
184
|
+
img='aslon_scaffold/sort_desc.gif'
|
185
|
+
end
|
186
|
+
|
187
|
+
if params[:order]==value && params[:sens]=='ASC'
|
188
|
+
sens='DESC'
|
189
|
+
img='aslon_scaffold/sort_asc.gif'
|
190
|
+
end
|
191
|
+
hlib=eval("#{model.gsub('_','/').camelize}.human_attribute_name(value)")
|
192
|
+
# sorting doesn't work with search
|
193
|
+
if request.env['QUERY_STRING'] != "method=get" && !value.include?('.')
|
194
|
+
s<<"<th scope='col' onclick=\"self.location.href = \'#{request.env['PATH_INFO']}?#{sel}&order=#{value}&sens=#{sens}\'; \">"
|
195
|
+
s<< hlib
|
196
|
+
s<<" "+image_tag(img, :border=>0, :style=>"vertical-align:middle") if (img)
|
197
|
+
s<<"</th>"
|
198
|
+
else
|
199
|
+
# s<< "<th scope='col'>"+l(key)+"</th>"
|
200
|
+
s<< "<th scope='col'>"+hlib+"</th>"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
s<<'</tr>'
|
205
|
+
s<<'</thead>'
|
206
|
+
# --------------------------------------------------------------------
|
207
|
+
# bas du tableau
|
208
|
+
# --------------------------------------------------------------------
|
209
|
+
s<< " <tfoot>
|
210
|
+
<tr>
|
211
|
+
<th scope='row'>#{info_titre_tableau}</th>
|
212
|
+
<td colspan='#{h.size-1}'> #{wp}</td>
|
213
|
+
</tr>
|
214
|
+
</tfoot>"
|
215
|
+
s<<'<tbody>'
|
216
|
+
# --------------------------------------------------------------------
|
217
|
+
# lignes du tableau
|
218
|
+
# --------------------------------------------------------------------
|
219
|
+
i=1
|
220
|
+
script="".force_encoding('utf-8')
|
221
|
+
for aLine in table
|
222
|
+
id=''
|
223
|
+
c_id=''
|
224
|
+
# ------------- création id de la ligne --------------------------
|
225
|
+
h.each do |lib|
|
226
|
+
begin
|
227
|
+
v=eval("aLine."+"#{lib}").to_s
|
228
|
+
rescue
|
229
|
+
v='nil'
|
230
|
+
end
|
231
|
+
id<<model+'_'+lib+'_'+ v.gsub(' ', '')
|
232
|
+
c_id=aLine.id
|
233
|
+
|
234
|
+
end
|
235
|
+
# ----------------------------------------------------------------
|
236
|
+
# ----------------------------------------------------------------
|
237
|
+
if i%2==0
|
238
|
+
s<<"<tr id='#{id}' class=#{c_id}>"
|
239
|
+
else
|
240
|
+
s<<"<tr class='odd #{c_id}' id='#{id}'>"
|
241
|
+
end
|
242
|
+
i+=1
|
243
|
+
# ----------------------------------------------------------------
|
244
|
+
cp=0
|
245
|
+
|
246
|
+
h.each do |lib|
|
247
|
+
|
248
|
+
local= I18n.locale
|
249
|
+
begin
|
250
|
+
v=url(eval("aLine."+"#{lib}").to_s)
|
251
|
+
rescue
|
252
|
+
v='nil'
|
253
|
+
end
|
254
|
+
s<<""
|
255
|
+
premiere_colonne=v
|
256
|
+
t=model.singularize.downcase + "_url(aLine)"
|
257
|
+
if cp==0
|
258
|
+
s<<("<th scope='row' "+"class='"+model.singularize.downcase+'_'+lib+'_'+ v+'_'+"'>" )
|
259
|
+
premiere_colonne= link_to(v, eval(t),:id=>'show')
|
260
|
+
else
|
261
|
+
s<<('<td '+"class='"+model+'_'+lib.to_s+'_'+ v+'_'+local.to_s+"'>")
|
262
|
+
end
|
263
|
+
|
264
|
+
s<< premiere_colonne
|
265
|
+
lik= url_for( eval(t))
|
266
|
+
# script << "<script>$('#{id}').observe('click',function(e) {window.location='#{lik}';},false)</script>"
|
267
|
+
# script << "<script>$('#{id}').observe('click',function(e) {window.location='#{lik}';},false)</script>"
|
268
|
+
# script << "<script>$('##{id}').click(function(){window.location='#{lik}';})</script>"
|
269
|
+
script << "<script>$('.#{c_id}').click(function(){window.location='#{lik}';})</script>"
|
270
|
+
if cp==0
|
271
|
+
s<<" </th>"
|
272
|
+
else
|
273
|
+
s<<" </td>"
|
274
|
+
end
|
275
|
+
cp+=1
|
276
|
+
end
|
277
|
+
s<<'</tr>'
|
278
|
+
|
279
|
+
end
|
280
|
+
s<<'</tbody>'
|
281
|
+
s<<"</table>"
|
282
|
+
s<<script
|
283
|
+
if table.size>0
|
284
|
+
return s
|
285
|
+
else
|
286
|
+
return "0 line"
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
#todo rendre multiplangues
|
292
|
+
def l(lib)
|
293
|
+
return lib.to_s.humanize
|
294
|
+
end
|
295
|
+
|
296
|
+
def llib(lib)
|
297
|
+
return lib.to_s.humanize if $l[lib]==nil
|
298
|
+
return "<b>"+$l[lib]+"</b>"
|
299
|
+
end
|
300
|
+
|
301
|
+
def hi(lib)
|
302
|
+
if lib.to_s==""
|
303
|
+
return "-"
|
304
|
+
else
|
305
|
+
h(lib)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def td (lib)
|
310
|
+
return "<td>"+hi(lib)+"</td>"
|
311
|
+
end
|
312
|
+
|
313
|
+
def tri(i)
|
314
|
+
if i%2==0
|
315
|
+
return "<tr class='pair'>"
|
316
|
+
else
|
317
|
+
return "<tr>"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def image_edit
|
322
|
+
return image_tag("aslon_scaffold/edit.gif", :border=>0, :style=>"vertical-align:middle")+"[Edit]"
|
323
|
+
end
|
324
|
+
|
325
|
+
def image_delete
|
326
|
+
return image_tag("aslon_scaffold/delete.gif", :border=>0, :style=>"vertical-align:middle")+"[Supp]"
|
327
|
+
end
|
328
|
+
|
329
|
+
def image_add
|
330
|
+
return image_tag("aslon_scaffold/add.gif", :border=>0, :style=>"vertical-align:middle",:id=>'add')+"[Ajouter]"
|
331
|
+
end
|
332
|
+
|
333
|
+
def image_zoom
|
334
|
+
return image_tag("aslon_scaffold/magnifier.png", :border=>0, :style=>"vertical-align:middle")+"[Voir]"
|
335
|
+
end
|
336
|
+
|
337
|
+
def image_folder
|
338
|
+
return image_tag("aslon_scaffold/folder.gif", :border=>0, :style=>"vertical-align:bottom")
|
339
|
+
end
|
340
|
+
|
341
|
+
def image_refresh
|
342
|
+
return image_tag("icons/mini/page_refresh.gif", :border=>0, :style=>"vertical-align:bottom")
|
343
|
+
end
|
344
|
+
|
345
|
+
def image_export
|
346
|
+
return image_tag("icons/mini/icon_download.gif", :border=>0, :style=>"vertical-align:middle")+"Export .csv"
|
347
|
+
end
|
348
|
+
|
349
|
+
def image_import
|
350
|
+
return image_tag("icons/mini/page_new.gif", :border=>0, :style=>"vertical-align:middle")+"Import"
|
351
|
+
end
|
352
|
+
|
353
|
+
|
354
|
+
# Outputs the error messages block.
|
355
|
+
# The first argument specifies a hash options:
|
356
|
+
# * :on => :products Also includes AR validation errors for @products
|
357
|
+
# * :clear => true Clears messages after displaying
|
358
|
+
# * :keep => true Keeps around messages for next response cycle
|
359
|
+
#
|
360
|
+
|
361
|
+
def mb
|
362
|
+
out = "é"
|
363
|
+
end
|
364
|
+
|
365
|
+
def message_block(options = {})
|
366
|
+
out = ""
|
367
|
+
|
368
|
+
[:back, :confirm, :error, :info, :warn, :notice].each do |type|
|
369
|
+
next if flash[type].nil? or flash[type].empty?
|
370
|
+
flash[type] = [flash[type]] unless flash[type].is_a?(Array)
|
371
|
+
|
372
|
+
out << "<div class=\"container #{type}\"><ul>\n"
|
373
|
+
flash[type].each {|msg| out << "<li>#{h(msg.to_s)}</li>\n"}
|
374
|
+
out << "</ul></div>\n"
|
375
|
+
|
376
|
+
flash[type] = nil if options[:clear]
|
377
|
+
flash.keep[type] if options[:keep]
|
378
|
+
end
|
379
|
+
|
380
|
+
if options[:on]
|
381
|
+
options[:on] = [options[:on]] unless options[:on].kind_of?(Array)
|
382
|
+
models = options[:on].map {|m| instance_variable_get("@" + m.to_s)}.select {|m| !m.nil?}
|
383
|
+
errors = models.inject([]) {|b, m| b += m.errors.full_messages}
|
384
|
+
|
385
|
+
if errors.size > 0
|
386
|
+
out << "<div class=\"container error\"><ul>\n"
|
387
|
+
errors.each {|msg| out << "<li>#{h(msg.to_s)}</li>\n"}
|
388
|
+
out << "</ul></div>\n"
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
content_tag(:div, out.html_safe, :id => 'message_block', :class => 'flash')
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
def hbutton_to(text, url, active=true)
|
397
|
+
out=''
|
398
|
+
out<<"<button type='button' onclick=\"JavaScript: window.location='"
|
399
|
+
out<< url_for(url)
|
400
|
+
out<<"'\">"
|
401
|
+
out<<text
|
402
|
+
out<<'</button> '
|
403
|
+
return out
|
404
|
+
end
|
405
|
+
|
406
|
+
def submit_action(form, lib, action)
|
407
|
+
button_to_function lib, "$('#{form}').action='#{action}';$('#{form}').submit();"
|
408
|
+
end
|
409
|
+
|
410
|
+
end
|