jorgchart-rails 0.1.0

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jorgchart-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Guillaume DOTT
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Jorgchart::Rails
2
+
3
+ jOrgChart for Rails. Bundled up jOrgChart into something useable with the Rails 3.1 asset pipeline
4
+
5
+ This gem include my forked version of jOrgChart (https://github.com/gdott9/jOrgChart/tree/my-master) which adds some features waiting to be merged.
6
+ Additionnal features :
7
+ * render list with multiple nodes on the first level (https://github.com/wesnolte/jOrgChart/pull/34)
8
+ * add an option to ignore space used by collapsed nodes (https://github.com/wesnolte/jOrgChart/pull/35)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'jorgchart-rails'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install jorgchart-rails
23
+
24
+ ## Usage
25
+
26
+ In application.js
27
+ ```
28
+ //= require jquery.jorgchart
29
+ ```
30
+
31
+ This gem comes with a stylesheet for default style. To use it, add the following line in application.css
32
+ ```
33
+ //= require jquery.jorgchart
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jorgchart-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "jorgchart-rails"
8
+ gem.version = Jorgchart::Rails::VERSION
9
+ gem.authors = ["Guillaume DOTT"]
10
+ gem.email = ["guillaume+github@dott.fr"]
11
+ gem.description = %q{jOrgChart for Rails 3 asset pipeline}
12
+ gem.summary = %q{This gem provides jOrgChart for your Rails 3 application.}
13
+ gem.homepage = "https://github.com/gdott9/jorgchart-rails"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "railties", "~> 3.0"
21
+ end
@@ -0,0 +1,7 @@
1
+ require "jorgchart-rails/version"
2
+
3
+ module Jorgchart
4
+ module Rails
5
+ class Engine < ::Rails::Engine; end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Jorgchart
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,256 @@
1
+ /**
2
+ * jQuery org-chart/tree plugin.
3
+ *
4
+ * Author: Wes Nolte
5
+ * http://twitter.com/wesnolte
6
+ *
7
+ * Based on the work of Mark Lee
8
+ * http://www.capricasoftware.co.uk
9
+ *
10
+ * Copyright (c) 2011 Wesley Nolte
11
+ * Dual licensed under the MIT and GPL licenses.
12
+ *
13
+ */
14
+ (function($) {
15
+
16
+ $.fn.jOrgChart = function(options) {
17
+ var opts = $.extend({}, $.fn.jOrgChart.defaults, options);
18
+ var $appendTo = $(opts.chartElement);
19
+
20
+ // build the tree
21
+ $this = $(this);
22
+ var $container = $("<div class='" + opts.chartClass + "'/>");
23
+ if($this.is("ul")) {
24
+ buildNodes($this, $container, opts);
25
+ }
26
+ else if($this.is("li")) {
27
+ buildNode($this, $container, 0, opts);
28
+ }
29
+ $appendTo.append($container);
30
+
31
+ // add drag and drop if enabled
32
+ if(opts.dragAndDrop){
33
+ $('div.node').draggable({
34
+ cursor : 'move',
35
+ distance : 40,
36
+ helper : 'clone',
37
+ opacity : 0.8,
38
+ revert : 'invalid',
39
+ revertDuration : 100,
40
+ snap : 'div.node.expanded',
41
+ snapMode : 'inner',
42
+ stack : 'div.node'
43
+ });
44
+
45
+ $('div.node').droppable({
46
+ accept : '.node',
47
+ activeClass : 'drag-active',
48
+ hoverClass : 'drop-hover'
49
+ });
50
+
51
+ // Drag start event handler for nodes
52
+ $('div.node').bind("dragstart", function handleDragStart( event, ui ){
53
+
54
+ var sourceNode = $(this);
55
+ sourceNode.parentsUntil('.node-container')
56
+ .find('*')
57
+ .filter('.node')
58
+ .droppable('disable');
59
+ });
60
+
61
+ // Drag stop event handler for nodes
62
+ $('div.node').bind("dragstop", function handleDragStop( event, ui ){
63
+
64
+ /* reload the plugin */
65
+ $(opts.chartElement).children().remove();
66
+ $this.jOrgChart(opts);
67
+ });
68
+
69
+ // Drop event handler for nodes
70
+ $('div.node').bind("drop", function handleDropEvent( event, ui ) {
71
+
72
+ var targetID = $(this).data("tree-node");
73
+ var targetLi = $this.find("li").filter(function() { return $(this).data("tree-node") === targetID; } );
74
+ var targetUl = targetLi.children('ul');
75
+
76
+ var sourceID = ui.draggable.data("tree-node");
77
+ var sourceLi = $this.find("li").filter(function() { return $(this).data("tree-node") === sourceID; } );
78
+ var sourceUl = sourceLi.parent('ul');
79
+
80
+ if (targetUl.length > 0){
81
+ targetUl.append(sourceLi);
82
+ } else {
83
+ targetLi.append("<ul></ul>");
84
+ targetLi.children('ul').append(sourceLi);
85
+ }
86
+
87
+ //Removes any empty lists
88
+ if (sourceUl.children().length === 0){
89
+ sourceUl.remove();
90
+ }
91
+
92
+ }); // handleDropEvent
93
+
94
+ } // Drag and drop
95
+ };
96
+
97
+ // Option defaults
98
+ $.fn.jOrgChart.defaults = {
99
+ chartElement : 'body',
100
+ depth : -1,
101
+ chartClass : "jOrgChart",
102
+ dragAndDrop: false,
103
+ ignoreSpace: false
104
+ };
105
+
106
+ function buildNodes($list, $appendTo, opts) {
107
+ var $table = $("<table cellpadding='0' cellspacing='0' border='0'/>");
108
+ var $tbody = $("<tbody/>");
109
+
110
+ // Construct the node container(s)
111
+ var $nodeRow = $("<tr/>");
112
+ $list.children("li").each(function(i, elem) {
113
+ var $td = $("<td class='node-container'/>");
114
+ $td.attr("colspan", 2);
115
+
116
+ buildNode($(elem), $td, 0, opts);
117
+ $nodeRow.append($td);
118
+ });
119
+
120
+ $tbody.append($nodeRow);
121
+ $table.append($tbody);
122
+ $appendTo.append($table);
123
+ }
124
+
125
+ var nodeCount = 0;
126
+ // Method that recursively builds the tree
127
+ function buildNode($node, $appendTo, level, opts) {
128
+ var $table = $("<table cellpadding='0' cellspacing='0' border='0'/>");
129
+ var $tbody = $("<tbody/>");
130
+
131
+ // Construct the node container(s)
132
+ var $nodeRow = $("<tr/>").addClass("node-cells");
133
+ var $nodeCell = $("<td/>").addClass("node-cell").attr("colspan", 2);
134
+ var $childNodes = $node.children("ul:first").children("li");
135
+ var $nodeDiv;
136
+
137
+ if($childNodes.length > 1) {
138
+ $nodeCell.attr("colspan", $childNodes.length * 2);
139
+ }
140
+ // Draw the node
141
+ // Get the contents - any markup except li and ul allowed
142
+ var $nodeContent = $node.clone()
143
+ .children("ul,li")
144
+ .remove()
145
+ .end()
146
+ .html();
147
+
148
+ //Increaments the node count which is used to link the source list and the org chart
149
+ nodeCount++;
150
+ $node.data("tree-node", nodeCount);
151
+ $nodeDiv = $("<div>").addClass("node")
152
+ .data("tree-node", nodeCount)
153
+ .append($nodeContent);
154
+
155
+ // Expand and contract nodes
156
+ if ($childNodes.length > 0) {
157
+ $nodeDiv.click(function() {
158
+ var $this = $(this);
159
+ var $tr = $this.closest("tr");
160
+
161
+ if($tr.hasClass('contracted')){
162
+ $this.css('cursor','n-resize');
163
+ $tr.removeClass('contracted').addClass('expanded');
164
+ $tr.nextAll("tr").css(opts.ignoreSpace ? 'display' : 'visibility', '');
165
+
166
+ // Update the <li> appropriately so that if the tree redraws collapsed/non-collapsed nodes
167
+ // maintain their appearance
168
+ $node.removeClass('collapsed');
169
+ }else{
170
+ $this.css('cursor','s-resize');
171
+ $tr.removeClass('expanded').addClass('contracted');
172
+ if(opts.ignoreSpace) { $tr.nextAll("tr").css('display', 'none'); }
173
+ else { $tr.nextAll("tr").css('visibility', 'hidden'); }
174
+
175
+ $node.addClass('collapsed');
176
+ }
177
+ });
178
+ }
179
+
180
+ $nodeCell.append($nodeDiv);
181
+ $nodeRow.append($nodeCell);
182
+ $tbody.append($nodeRow);
183
+
184
+ if($childNodes.length > 0) {
185
+ // if it can be expanded then change the cursor
186
+ $nodeDiv.css('cursor','n-resize');
187
+
188
+ // recurse until leaves found (-1) or to the level specified
189
+ if(opts.depth == -1 || (level+1 < opts.depth)) {
190
+ var $downLineRow = $("<tr/>");
191
+ var $downLineCell = $("<td/>").attr("colspan", $childNodes.length*2);
192
+ $downLineRow.append($downLineCell);
193
+
194
+ // draw the connecting line from the parent node to the horizontal line
195
+ $downLine = $("<div></div>").addClass("line down");
196
+ $downLineCell.append($downLine);
197
+ $tbody.append($downLineRow);
198
+
199
+ // Draw the horizontal lines
200
+ var $linesRow = $("<tr/>");
201
+ $childNodes.each(function() {
202
+ var $left = $("<td>&nbsp;</td>").addClass("line left top");
203
+ var $right = $("<td>&nbsp;</td>").addClass("line right top");
204
+ $linesRow.append($left).append($right);
205
+ });
206
+
207
+ // horizontal line shouldn't extend beyond the first and last child branches
208
+ $linesRow.find("td:first")
209
+ .removeClass("top")
210
+ .end()
211
+ .find("td:last")
212
+ .removeClass("top");
213
+
214
+ $tbody.append($linesRow);
215
+ var $childNodesRow = $("<tr/>");
216
+ $childNodes.each(function() {
217
+ var $td = $("<td class='node-container'/>");
218
+ $td.attr("colspan", 2);
219
+ // recurse through children lists and items
220
+ buildNode($(this), $td, level+1, opts);
221
+ $childNodesRow.append($td);
222
+ });
223
+
224
+ }
225
+ $tbody.append($childNodesRow);
226
+ }
227
+
228
+ // any classes on the LI element get copied to the relevant node in the tree
229
+ // apart from the special 'collapsed' class, which collapses the sub-tree at this point
230
+ if ($node.attr('class') != undefined) {
231
+ var classList = $node.attr('class').split(/\s+/);
232
+ $.each(classList, function(index,item) {
233
+ if (item == 'collapsed') {
234
+ console.log($node);
235
+ if(opts.ignoreSpace) { $nodeRow.nextAll('tr').css('display', 'none'); }
236
+ else { $nodeRow.nextAll('tr').css('visibility', 'hidden'); }
237
+ $nodeRow.removeClass('expanded');
238
+ $nodeRow.addClass('contracted');
239
+ $nodeDiv.css('cursor','s-resize');
240
+ } else {
241
+ $nodeDiv.addClass(item);
242
+ }
243
+ });
244
+ }
245
+
246
+ $table.append($tbody);
247
+ $appendTo.append($table);
248
+
249
+ /* Prevent trees collapsing if a link inside a node is clicked */
250
+ $nodeDiv.children('a').click(function(e){
251
+ console.log(e);
252
+ e.stopPropagation();
253
+ });
254
+ };
255
+
256
+ })(jQuery);
@@ -0,0 +1,65 @@
1
+ /* Basic styling */
2
+ /* Draw the lines */
3
+ .jOrgChart .line {
4
+ height: 20px;
5
+ width: 50%;
6
+ }
7
+
8
+ .jOrgChart .down {
9
+ background-color: black;
10
+ width: 2px;
11
+ margin: 0px auto;
12
+ }
13
+
14
+ .jOrgChart .top {
15
+ border-top: 2px solid black;
16
+ }
17
+
18
+ .jOrgChart .left {
19
+ border-right: 1px solid black;
20
+ }
21
+
22
+ .jOrgChart .right {
23
+ border-left: 1px solid black;
24
+ }
25
+
26
+ /* node cell */
27
+ .jOrgChart td {
28
+ text-align: center;
29
+ vertical-align: top;
30
+ padding: 0;
31
+ margin: 0;
32
+ float: none;
33
+ border: none;
34
+ }
35
+
36
+ .jOrgChart tr, .jOrgChart table {
37
+ border: none;
38
+ }
39
+
40
+ .jOrgChart table {
41
+ border-collapse: separate;
42
+ border-spacing: 0;
43
+ }
44
+
45
+ /* The node */
46
+ .jOrgChart .node {
47
+ background-color: #fff;
48
+ border: 1px solid black;
49
+ display: inline-block;
50
+ width: 96px;
51
+ height: 60px;
52
+ z-index: 10;
53
+ margin: 0 2px;
54
+ }
55
+
56
+ /* jQuery drag 'n drop */
57
+
58
+ .drag-active {
59
+ border-style: dotted !important;
60
+ }
61
+
62
+ .drop-hover {
63
+ border-style: solid !important;
64
+ border-color: #f00 !important;
65
+ }
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jorgchart-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guillaume DOTT
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ description: jOrgChart for Rails 3 asset pipeline
31
+ email:
32
+ - guillaume+github@dott.fr
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - jorgchart-rails.gemspec
43
+ - lib/jorgchart-rails.rb
44
+ - lib/jorgchart-rails/version.rb
45
+ - vendor/assets/javascripts/jquery.jorgchart.js
46
+ - vendor/assets/stylesheets/jquery.jorgchart.css
47
+ homepage: https://github.com/gdott9/jorgchart-rails
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: This gem provides jOrgChart for your Rails 3 application.
71
+ test_files: []