sylrplm_ext 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -2,3 +2,54 @@ sylrplm_ext
2
2
  ===========
3
3
 
4
4
  PLM extensions
5
+
6
+ Installation
7
+ ------------
8
+ install directly the gem:
9
+ gem install "sylrplm_ext"
10
+
11
+ or
12
+
13
+ complete the Gemfile of your project:
14
+ gem "sylrplm_ext", git: "git://github.com/sylvani/sylrplm_ext.git"
15
+
16
+
17
+ Documentation
18
+ -------------
19
+
20
+ = Select in/out
21
+ # == Role: create two combobox with an arrow to transfer selected values from the left (possible values) to the right (selected values)
22
+ # == Arguments
23
+ # * +form+ Formulaire html created by edition view
24
+ # * +object+ \Object being edited
25
+ # * +values+ Array of objects defining the values
26
+ # * +field+ The field of value to show in select
27
+ # * +assoc_name+ name of the association between object and "object value" / example :ongroup for subscription to groups. Contient le nom de l'association, example :ongroup pour subscription vers les groupes
28
+ # == Usage
29
+ # === Calling view
30
+ # <%= select_inout(form, @subscription, @ongroups, :name, :ongroup) %>
31
+ # Note: in case of no velues, the default is the first object in list of values / Si pas de valeur, on prend le nom par defaut dans la le 1er objet de la liste des valeurs :group
32
+ #
33
+
34
+ = Select in list
35
+ # == Role: this function permit a selection in a list of objects in another window
36
+ # <em>the field in a first window is updated with the value selected in the second</em>
37
+ # == Arguments
38
+ # * +sym_objfrom+ - \Object name to edit
39
+ # * +sym_objto+ - \Object to select
40
+ # * +val_objtoselect+ - Actual value of the object to select
41
+ # * +:control+ - Controller of the object to select
42
+ # == Usage
43
+ # === Calling view
44
+ # During datafile edition, I want to choose the responsible:
45
+ # <%= f.label t("label_responsible") %>
46
+ # <%= \select_in_list(:datafile, :owner, @datafile.owner.login, :users) %>
47
+ # === Result
48
+ # hidden_field("datafile" , "owner_id")
49
+ # text_field_tag("datafile_owner_display", value of @datafile.owner.login, :disabled => true)
50
+ # link_to(h_img_btn("btn_select"), {:controller => "users", :todo => "select", :html_ident => "datafile_owner"} , {:target => "_blank", :class => 'menu_bas'})"
51
+ # == Impact on other components
52
+ # the 'index' view of the object to select can be modified to show or not the menus or anything else
53
+ # <% unless param_equals?("todo", "select") %>
54
+ #
55
+
@@ -1,5 +1,3 @@
1
1
  require "sylrplm_ext/version"
2
2
 
3
- module SylrplmExt
4
- # Your code goes here...
5
- end
3
+ require "sylrplm_ext/sylrplm_extensions_helpers"
@@ -0,0 +1,110 @@
1
+ // Place your application-specific JavaScript functions and classes here
2
+ // This file is automatically included by javascript_include_tag :defaults
3
+
4
+ function selectInOutFill(select_ref_id) {
5
+ //alert('selectInOutFill:'+select_ref_id);
6
+ select_from = byId(select_ref_id);
7
+ select_to = byId(select_ref_id + '_in');
8
+ selectInOutFill_(select_from, select_to, 'in');
9
+ select_to = byId(select_ref_id + '_out');
10
+ selectInOutFill_(select_from, select_to, 'out');
11
+ }
12
+
13
+ function selectInOutFill_(select_from, select_to, in_out) {
14
+ if(in_out == 'in') {
15
+ ifselect = true;
16
+ } else {
17
+ ifselect = false;
18
+ }
19
+ var length_from = select_from.length;
20
+ //alert('selectInOutFill_:'+select_from+":"+ select_from.length);
21
+ if(!length_from)
22
+ return null;
23
+ for(var i = 0; i < length_from; i++) {
24
+ var opt = select_from.options[i];
25
+ if(opt.selected == ifselect) {
26
+ newopt = document.createElement("option")
27
+ newopt.value = opt.value
28
+ newopt.innerHTML = opt.innerHTML
29
+ select_to.appendChild(newopt);
30
+ }
31
+ }
32
+ }
33
+
34
+ function selectInOutAdd(select_id) {
35
+ select_ref = byId(select_id);
36
+ select_from = byId(select_id + "_out");
37
+ select_to = byId(select_id + "_in");
38
+ selectInOutMove_(select_ref, select_from, select_to, true);
39
+ }
40
+
41
+ function selectInOutRemove(select_id) {
42
+ select_ref = byId(select_id);
43
+ select_from = byId(select_id + "_in");
44
+ select_to = byId(select_id + "_out");
45
+ selectInOutMove_(select_ref, select_from, select_to, false);
46
+ }
47
+
48
+ function selectInOutMove_(select_ref, select_from, select_to, to_select) {
49
+ var length_ref = select_ref.length;
50
+ var length_from = select_from.length;
51
+ var length_to = select_to.length;
52
+ if(!length_ref || !length_from)
53
+ return null;
54
+ var i = 0;
55
+ var to_move = [];
56
+ for( i = 0; i < length_from; i++) {
57
+ var opt = select_from.options[i];
58
+ if(opt.selected) {
59
+ for(var j = 0; j < length_ref; j++) {
60
+ var opt_ref = select_ref.options[j];
61
+ if(opt.value == opt_ref.value) {
62
+ opt_ref.selected = to_select;
63
+ }
64
+ }
65
+ opt.selected = false;
66
+ to_move.push(opt)
67
+ }
68
+ }
69
+ for( i = 0; i < to_move.length; i++) {
70
+ select_to.appendChild(to_move[i]);
71
+ }
72
+ }
73
+
74
+ var select_html;
75
+ function selectActive(check, select_id) {
76
+ var select = byId(select_id);
77
+ if(select) {
78
+ //select.readonly = (check.checked ? undefined : "readonly");
79
+ //alert ('selectActive:check='+check.checked+' select='+select.readonly)
80
+ if(select.innerHTML) {
81
+ select_html = select.innerHTML
82
+ }
83
+ if(!check.checked) {
84
+ select.innerHTML = null;
85
+ } else {
86
+ select.innerHTML = select_html
87
+ }
88
+ }
89
+ }
90
+
91
+ /*
92
+ * use by helper select_in_list
93
+ * met a jour un champ de la fenetre appelante
94
+ * appelle par les vues index utilisees en mode (todo) select
95
+ * @param html_ident: id (au sens html) du champ a mettre a jour
96
+ * @param id: id (au sens bd) du champ a mettre a jour
97
+ * @param display: valeur a afficher dans le champ
98
+ */
99
+ function callSelect(html_ident, id, display) {
100
+ win=top.opener;
101
+ field_id=win.document.getElementById(html_ident+'_id');
102
+ field_display=win.document.getElementById(html_ident+'_display');
103
+ //alert ('win='+win+' html_ident='+html_ident+':'+field_id.value+' display='+field_display.value);
104
+ field_id.value=id;
105
+ field_display.value=display;
106
+ //alert (' id='+field_id.value+' display='+field_display.value);
107
+ window.close();
108
+ win.focus();
109
+
110
+ }
@@ -0,0 +1,109 @@
1
+ module SylrplmExt
2
+ module SylrplmExtensionsHelper
3
+ #
4
+ # == Role: this function permit a selection in a list of objects in another window
5
+ # <em>the field in a first window is updated with the value selected in the second</em>
6
+ # == Arguments
7
+ # * +sym_objfrom+ - \Object name to edit
8
+ # * +sym_objto+ - \Object to select
9
+ # * +val_objtoselect+ - Actual value of the object to select
10
+ # * +:control+ - Controller of the object to select
11
+ # == Usage
12
+ # === Calling view
13
+ # During datafile edition, I want to choice the responsible:
14
+ # <%= f.label t("label_responsible") %>
15
+ # <%= \select_in_list(:datafile, :owner, @datafile.owner.login, :users) %>
16
+ # === Result
17
+ # hidden_field("datafile" , "owner_id")
18
+ # text_field_tag("datafile_owner_display", value of @datafile.owner.login, :disabled => true)
19
+ # link_to(h_img_btn("btn_select"), {:controller => "users", :todo => "select", :html_ident => "datafile_owner"} , {:target => "_blank", :class => 'menu_bas'})"
20
+ # == Impact on other components
21
+ # the 'index' view of the object to select can be modified to show or not the menus or anything else
22
+ # <% unless param_equals?("todo", "select") %>
23
+ #
24
+ def select_in_list (sym_objfrom, sym_objto, val_objtoselect, control)
25
+ ret=""
26
+ ret<< hidden_field(sym_objfrom , "#{sym_objto}_id")
27
+ ret<< text_field_tag("#{sym_objfrom}_#{sym_objto}_display", val_objtoselect, :disabled => true)
28
+ ret<< link_to("...", {:controller => control, :todo => "select", :html_ident => "#{sym_objfrom}_#{sym_objto}"} , {:target => "_blank", :class => 'menu_bas',:title=>t("btn_select")})
29
+ ret
30
+ end
31
+
32
+ #
33
+ # == Role: create two combobox with an arrow to transfer selected values from the left (possible values) to the right (selected values)
34
+ # == Arguments
35
+ # * +form+ Formulaire html created by edition view
36
+ # * +object+ \Object being edited
37
+ # * +values+ Array of objects defining the values
38
+ # * +field+ The field of value to show in select
39
+ # * +assoc_name+ name of the association between object and "object value" / example :ongroup for subscription to groups. Contient le nom de l'association, example :ongroup pour subscription vers les groupes
40
+ # == Usage
41
+ # === Calling view
42
+ # <%= select_inout(form, @subscription, @ongroups, :name, :ongroup) %>
43
+ # Note: in case of no velues, the default is the first object in list of values / Si pas de valeur, on prend le nom par defaut dans la le 1er objet de la liste des valeurs :group
44
+ #
45
+ def select_inout(form, object, values, field, assoc_name=nil)
46
+ fname = "#{self.class.name}.#{__method__}"
47
+ #LOG.debug (fname){"object=#{object}"}
48
+ #LOG.debug (fname){"values=#{values}, field=#{field}"}
49
+ html = ""
50
+ unless values.nil? || values.count == 0
51
+ #user
52
+ mdl_object=object.model_name
53
+ #group
54
+ if assoc_name.nil?
55
+ mdl_assoc = values[0].model_name
56
+ else
57
+ mdl_assoc = assoc_name
58
+ end
59
+ #user_groups
60
+ select_id="#{mdl_object}_#{mdl_assoc}_ids"
61
+ #user[role_ids][]
62
+ select_name="#{mdl_object}[#{mdl_assoc}_ids][]"
63
+ #role_ids
64
+ method=("#{mdl_assoc}_ids").to_sym
65
+ #LOG.debug (fname){"method=#{method}"}
66
+ #the_selected=object.method(method).call: ko dans certains cas (securite!!)
67
+ the_selected=object.send(method)
68
+ #puts "select_inout:object="+object.model_name+" method="+method.to_s+" sel="+the_selected.inspect
69
+ #label_user_groups_out, label_user_groups_in
70
+ label_out=t("label_"+select_id+"_out")
71
+ label_in=t("label_"+select_id+"_in")
72
+ nb=[values.count+1, 10].min
73
+ html += "<div style='display: none;'>"
74
+ html += form.collection_select(method, values, :id, field, {}, {:id => select_id, :size => nb, :multiple => :true, :name => select_name, :selected => the_selected})
75
+ html += "</div>"
76
+ html += "<table>"
77
+ html += "<tr>"
78
+ html += "<th>#{label_out}</th>"
79
+ html += "<th></th>"
80
+ html += "<th>#{label_in}</th>"
81
+ html += "</tr>"
82
+ html += "<tr>"
83
+ #html += "<td>mdl_object:#{mdl_object} mdl_assoc:#{mdl_assoc} select_id:#{select_id} select_name:#{select_name} method:#{method} : #{the_selected.inspect}</td>"
84
+ html += "<td><select id='#{select_id}_out' multiple='multiple' name='#{select_id}_out' size=#{nb}></select></td>"
85
+ html += "<td><a onclick=\"selectInOutAdd('#{select_id}'); return true;\" title=\"#{t('button_add')}\">#{h_img('select_inout/select_add')}</a>"
86
+ html += "<br/>"
87
+ html += "<a onclick= \"selectInOutRemove('#{select_id}'); return true;\" title=\"#{t('button_remove')}\">#{h_img('select_inout/select_remove')}</a></td>"
88
+ html += "<td><select id='#{select_id}_in' multiple='multiple' name='#{select_id}_in' size=#{nb}></select></td>"
89
+ html += "</tr>"
90
+ html += "</table>"
91
+ html += "<script>selectInOutFill('#{select_id}')</script>"
92
+ end
93
+ html
94
+ end
95
+
96
+ #
97
+ # combo box: select able to return null value
98
+ #
99
+ def select_with_empty(form, object, attribute, values, id, method)
100
+ # id du select = role_father_id
101
+ select_id = object.model_name+'_'+attribute.to_s
102
+ html = "<p>#{t(:label_select_active)}</p>"
103
+ html += check_box_tag(:select_active, "no", "false", :onclick=>"selectActive(this, '#{select_id}'); return true;")
104
+ html += form.collection_select(attribute, values, id, method)
105
+ html
106
+ end
107
+
108
+ end
109
+ end
@@ -1,3 +1,3 @@
1
1
  module SylrplmExt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sylrplm_ext
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - sylvani
@@ -29,6 +29,8 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - lib/sylrplm_ext.rb
32
+ - lib/sylrplm_ext/sylrplm_extensions.js
33
+ - lib/sylrplm_ext/sylrplm_extensions_helper.rb
32
34
  - lib/sylrplm_ext/version.rb
33
35
  - sylrplm_ext.gemspec
34
36
  homepage: ""