django-bom 1.262__py3-none-any.whl
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.
Potentially problematic release.
This version of django-bom might be problematic. Click here for more details.
- bom/__init__.py +1 -0
- bom/admin.py +207 -0
- bom/apps.py +8 -0
- bom/auth_backends.py +47 -0
- bom/base_classes.py +31 -0
- bom/constants.py +217 -0
- bom/context_processors.py +9 -0
- bom/csv_headers.py +252 -0
- bom/decorators.py +32 -0
- bom/form_fields.py +59 -0
- bom/forms.py +1328 -0
- bom/helpers.py +367 -0
- bom/local_settings.py +35 -0
- bom/migrations/0001_initial.py +135 -0
- bom/migrations/0002_auto_20180908_2151.py +24 -0
- bom/migrations/0003_sellerpart_data_source.py +18 -0
- bom/migrations/0004_auto_20180911_0011.py +18 -0
- bom/migrations/0005_auto_20181007_1934.py +56 -0
- bom/migrations/0006_auto_20181007_1949.py +41 -0
- bom/migrations/0007_auto_20181009_0256.py +19 -0
- bom/migrations/0008_auto_20181030_0427.py +19 -0
- bom/migrations/0009_subpart_reference.py +18 -0
- bom/migrations/0010_auto_20181202_0733.py +23 -0
- bom/migrations/0011_auto_20181202_2113.py +22 -0
- bom/migrations/0012_partchangehistory.py +30 -0
- bom/migrations/0013_auto_20190222_1631.py +19 -0
- bom/migrations/0014_auto_20190223_2353.py +18 -0
- bom/migrations/0015_auto_20190303_1915.py +136 -0
- bom/migrations/0016_auto_20190405_2308.py +58 -0
- bom/migrations/0017_auto_20190616_1912.py +19 -0
- bom/migrations/0018_auto_20190616_2143.py +24 -0
- bom/migrations/0019_auto_20190624_1246.py +45 -0
- bom/migrations/0020_auto_20190627_0207.py +38 -0
- bom/migrations/0021_auto_20190627_0428.py +23 -0
- bom/migrations/0022_auto_20190811_2140.py +35 -0
- bom/migrations/0023_auto_20191205_2351.py +255 -0
- bom/migrations/0024_auto_20191214_1342.py +89 -0
- bom/migrations/0025_auto_20191221_1907.py +38 -0
- bom/migrations/0026_auto_20191222_2258.py +22 -0
- bom/migrations/0027_auto_20191222_2347.py +17 -0
- bom/migrations/0028_partrevision_displayable_synopsis.py +74 -0
- bom/migrations/0029_auto_20191231_1630.py +23 -0
- bom/migrations/0030_auto_20200101_2253.py +22 -0
- bom/migrations/0031_auto_20200104_1352.py +38 -0
- bom/migrations/0032_auto_20200126_1806.py +27 -0
- bom/migrations/0033_auto_20200203_0618.py +29 -0
- bom/migrations/0034_auto_20200222_0359.py +30 -0
- bom/migrations/0035_auto_20200303_0111.py +34 -0
- bom/migrations/0036_auto_20200303_0538.py +17 -0
- bom/migrations/0037_auto_20200405_1642.py +44 -0
- bom/migrations/0038_auto_20200422_0504.py +19 -0
- bom/migrations/0039_auto_20200929_2315.py +41 -0
- bom/migrations/0040_alter_organization_currency.py +19 -0
- bom/migrations/0041_organization_subscription_quantity.py +18 -0
- bom/migrations/0042_auto_20210720_2137.py +23 -0
- bom/migrations/0043_auto_20211123_0157.py +24 -0
- bom/migrations/0044_auto_20220831_1241.py +23 -0
- bom/migrations/0045_sellerpart_link.py +18 -0
- bom/migrations/0046_alter_sellerpart_unique_together.py +17 -0
- bom/migrations/0047_sellerpart_seller_part_number.py +18 -0
- bom/migrations/0048_rename_part_organization_number_class_bom_part_organiz_b333d6_idx_and_more.py +1017 -0
- bom/migrations/0049_alter_assembly_id_alter_assemblysubparts_id_and_more.py +99 -0
- bom/migrations/0050_alter_organization_options.py +17 -0
- bom/migrations/0051_alter_manufacturer_organization_and_more.py +41 -0
- bom/migrations/0052_remove_partrevision_attribute_and_more.py +584 -0
- bom/migrations/__init__.py +0 -0
- bom/models.py +886 -0
- bom/part_bom.py +192 -0
- bom/settings.py +262 -0
- bom/static/bom/css/dashboard.css +17 -0
- bom/static/bom/css/jquery.treetable.css +28 -0
- bom/static/bom/css/materialize.min.css +13 -0
- bom/static/bom/css/part-info.css +15 -0
- bom/static/bom/css/style.css +482 -0
- bom/static/bom/css/tablesorter-theme.materialize.css +176 -0
- bom/static/bom/css/treetable-theme.css +42 -0
- bom/static/bom/doc/sample_part_classes.csv +38 -0
- bom/static/bom/doc/test_bom.csv +6 -0
- bom/static/bom/doc/test_bom_5_intelligent.csv +4 -0
- bom/static/bom/doc/test_full_bom.csv +37 -0
- bom/static/bom/doc/test_new_parts.csv +5 -0
- bom/static/bom/doc/test_new_parts_5_intelligent.csv +5 -0
- bom/static/bom/img/_ionicons_svg_md-arrow-dropdown.svg +1 -0
- bom/static/bom/img/_ionicons_svg_md-arrow-dropright.svg +1 -0
- bom/static/bom/img/favicon.ico +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_dark_disabled_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_dark_focus_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_dark_normal_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_dark_pressed_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_light_disabled_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_light_focus_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_light_normal_web.png +0 -0
- bom/static/bom/img/google/web/1x/btn_google_signin_light_pressed_web.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_dark_disabled_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_dark_focus_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_dark_normal_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_dark_pressed_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_light_disabled_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_light_focus_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_light_normal_web@2x.png +0 -0
- bom/static/bom/img/google/web/2x/btn_google_signin_light_pressed_web@2x.png +0 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_disabled_ios.eps +814 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_disabled_ios.svg +24 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_focus_ios.eps +1866 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_focus_ios.svg +51 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_normal_ios.eps +1031 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_normal_ios.svg +50 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_pressed_ios.eps +1031 -0
- bom/static/bom/img/google/web/vector/btn_google_dark_pressed_ios.svg +50 -0
- bom/static/bom/img/google/web/vector/btn_google_light_disabled_ios.eps +814 -0
- bom/static/bom/img/google/web/vector/btn_google_light_disabled_ios.svg +24 -0
- bom/static/bom/img/google/web/vector/btn_google_light_focus_ios.eps +1837 -0
- bom/static/bom/img/google/web/vector/btn_google_light_focus_ios.svg +44 -0
- bom/static/bom/img/google/web/vector/btn_google_light_normal_ios.eps +1002 -0
- bom/static/bom/img/google/web/vector/btn_google_light_normal_ios.svg +43 -0
- bom/static/bom/img/google/web/vector/btn_google_light_pressed_ios.eps +1002 -0
- bom/static/bom/img/google/web/vector/btn_google_light_pressed_ios.svg +43 -0
- bom/static/bom/img/google_drive_logo.svg +1 -0
- bom/static/bom/img/indabom.png +0 -0
- bom/static/bom/img/mouser.png +0 -0
- bom/static/bom/img/octopart_blue.svg +19 -0
- bom/static/bom/js/formset-handler.js +65 -0
- bom/static/bom/js/jquery-3.4.1.min.js +2 -0
- bom/static/bom/js/jquery.ba-floatingscrollbar.min.js +10 -0
- bom/static/bom/js/jquery.treetable.js +629 -0
- bom/static/bom/js/materialize.min.js +6 -0
- bom/templates/bom/account-delete.html +23 -0
- bom/templates/bom/add-manufacturer-part.html +66 -0
- bom/templates/bom/add-sellerpart.html +93 -0
- bom/templates/bom/base-menu.html +16 -0
- bom/templates/bom/base.html +129 -0
- bom/templates/bom/bom-action-btn.html +23 -0
- bom/templates/bom/bom-action-table.html +57 -0
- bom/templates/bom/bom-base-menu.html +6 -0
- bom/templates/bom/bom-base.html +24 -0
- bom/templates/bom/bom-form-modal.html +36 -0
- bom/templates/bom/bom-form.html +30 -0
- bom/templates/bom/bom-modal-add-users.html +49 -0
- bom/templates/bom/bom-signup.html +12 -0
- bom/templates/bom/components/bom-flat.html +131 -0
- bom/templates/bom/components/bom-indented.html +237 -0
- bom/templates/bom/components/manufacturer-part-list.html +270 -0
- bom/templates/bom/components/seller-part-list.html +62 -0
- bom/templates/bom/create-part.html +65 -0
- bom/templates/bom/dashboard-menu.html +15 -0
- bom/templates/bom/dashboard.html +303 -0
- bom/templates/bom/edit-manufacturer-part.html +72 -0
- bom/templates/bom/edit-part-class.html +120 -0
- bom/templates/bom/edit-part.html +67 -0
- bom/templates/bom/edit-quantity-of-measure.html +119 -0
- bom/templates/bom/edit-user-meta.html +70 -0
- bom/templates/bom/help.html +1356 -0
- bom/templates/bom/manufacturer-info.html +82 -0
- bom/templates/bom/manufacturers.html +97 -0
- bom/templates/bom/nothing-to-see.html +15 -0
- bom/templates/bom/organization-create.html +135 -0
- bom/templates/bom/part-info.html +448 -0
- bom/templates/bom/part-revision-display.html +50 -0
- bom/templates/bom/part-revision-edit.html +39 -0
- bom/templates/bom/part-revision-manage-bom.html +115 -0
- bom/templates/bom/part-revision-new.html +57 -0
- bom/templates/bom/part-revision-release.html +41 -0
- bom/templates/bom/search-help.html +101 -0
- bom/templates/bom/seller-info.html +82 -0
- bom/templates/bom/sellers.html +97 -0
- bom/templates/bom/settings.html +734 -0
- bom/templates/bom/signup.html +28 -0
- bom/templates/bom/subscription_panel.html +16 -0
- bom/templates/bom/table_of_contents.html +47 -0
- bom/templates/bom/upload-bom.html +111 -0
- bom/templates/bom/upload-parts-help.html +103 -0
- bom/templates/bom/upload-parts.html +50 -0
- bom/templates/registration/login.html +39 -0
- bom/tests.py +1592 -0
- bom/third_party_apis/__init__.py +0 -0
- bom/third_party_apis/base_api.py +51 -0
- bom/third_party_apis/google_drive.py +166 -0
- bom/third_party_apis/mouser.py +132 -0
- bom/third_party_apis/test_apis.py +24 -0
- bom/urls.py +100 -0
- bom/utils.py +228 -0
- bom/validators.py +23 -0
- bom/views/__init__.py +0 -0
- bom/views/json_views.py +55 -0
- bom/views/views.py +1773 -0
- bom/wsgi.py +16 -0
- django_bom-1.262.dist-info/METADATA +206 -0
- django_bom-1.262.dist-info/RECORD +191 -0
- django_bom-1.262.dist-info/WHEEL +5 -0
- django_bom-1.262.dist-info/licenses/LICENSE +674 -0
- django_bom-1.262.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* jQuery treetable Plugin 3.2.0
|
|
3
|
+
* http://ludo.cubicphuse.nl/jquery-treetable
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2013, Ludo van den Boom
|
|
6
|
+
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
7
|
+
*/
|
|
8
|
+
(function($) {
|
|
9
|
+
var Node, Tree, methods;
|
|
10
|
+
|
|
11
|
+
Node = (function() {
|
|
12
|
+
function Node(row, tree, settings) {
|
|
13
|
+
var parentId;
|
|
14
|
+
|
|
15
|
+
this.row = row;
|
|
16
|
+
this.tree = tree;
|
|
17
|
+
this.settings = settings;
|
|
18
|
+
|
|
19
|
+
// TODO Ensure id/parentId is always a string (not int)
|
|
20
|
+
this.id = this.row.data(this.settings.nodeIdAttr);
|
|
21
|
+
|
|
22
|
+
// TODO Move this to a setParentId function?
|
|
23
|
+
parentId = this.row.data(this.settings.parentIdAttr);
|
|
24
|
+
if (parentId != null && parentId !== "") {
|
|
25
|
+
this.parentId = parentId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.treeCell = $(this.row.children(this.settings.columnElType)[this.settings.column]);
|
|
29
|
+
this.expander = $(this.settings.expanderTemplate);
|
|
30
|
+
this.indenter = $(this.settings.indenterTemplate);
|
|
31
|
+
this.children = [];
|
|
32
|
+
this.initialized = false;
|
|
33
|
+
this.treeCell.prepend(this.indenter);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Node.prototype.addChild = function(child) {
|
|
37
|
+
return this.children.push(child);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Node.prototype.ancestors = function() {
|
|
41
|
+
var ancestors, node;
|
|
42
|
+
node = this;
|
|
43
|
+
ancestors = [];
|
|
44
|
+
while (node = node.parentNode()) {
|
|
45
|
+
ancestors.push(node);
|
|
46
|
+
}
|
|
47
|
+
return ancestors;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Node.prototype.collapse = function() {
|
|
51
|
+
if (this.collapsed()) {
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.row.removeClass("expanded").addClass("collapsed");
|
|
56
|
+
|
|
57
|
+
this._hideChildren();
|
|
58
|
+
this.expander.attr("title", this.settings.stringExpand);
|
|
59
|
+
|
|
60
|
+
if (this.initialized && this.settings.onNodeCollapse != null) {
|
|
61
|
+
this.settings.onNodeCollapse.apply(this);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return this;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
Node.prototype.collapsed = function() {
|
|
68
|
+
return this.row.hasClass("collapsed");
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// TODO destroy: remove event handlers, expander, indenter, etc.
|
|
72
|
+
|
|
73
|
+
Node.prototype.expand = function() {
|
|
74
|
+
if (this.expanded()) {
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.row.removeClass("collapsed").addClass("expanded");
|
|
79
|
+
|
|
80
|
+
if (this.initialized && this.settings.onNodeExpand != null) {
|
|
81
|
+
this.settings.onNodeExpand.apply(this);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ($(this.row).is(":visible")) {
|
|
85
|
+
this._showChildren();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.expander.attr("title", this.settings.stringCollapse);
|
|
89
|
+
|
|
90
|
+
return this;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
Node.prototype.expanded = function() {
|
|
94
|
+
return this.row.hasClass("expanded");
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
Node.prototype.hide = function() {
|
|
98
|
+
this._hideChildren();
|
|
99
|
+
this.row.hide();
|
|
100
|
+
return this;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
Node.prototype.isBranchNode = function() {
|
|
104
|
+
if(this.children.length > 0 || this.row.data(this.settings.branchAttr) === true) {
|
|
105
|
+
return true;
|
|
106
|
+
} else {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
Node.prototype.updateBranchLeafClass = function(){
|
|
112
|
+
this.row.removeClass('branch');
|
|
113
|
+
this.row.removeClass('leaf');
|
|
114
|
+
this.row.addClass(this.isBranchNode() ? 'branch' : 'leaf');
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
Node.prototype.level = function() {
|
|
118
|
+
return this.ancestors().length;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
Node.prototype.parentNode = function() {
|
|
122
|
+
if (this.parentId != null) {
|
|
123
|
+
return this.tree[this.parentId];
|
|
124
|
+
} else {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
Node.prototype.removeChild = function(child) {
|
|
130
|
+
var i = $.inArray(child, this.children);
|
|
131
|
+
return this.children.splice(i, 1)
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
Node.prototype.render = function() {
|
|
135
|
+
var handler,
|
|
136
|
+
settings = this.settings,
|
|
137
|
+
target;
|
|
138
|
+
|
|
139
|
+
if (settings.expandable === true && this.isBranchNode()) {
|
|
140
|
+
handler = function(e) {
|
|
141
|
+
$(this).parents("table").treetable("node", $(this).parents("tr").data(settings.nodeIdAttr)).toggle();
|
|
142
|
+
return e.preventDefault();
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
this.indenter.html(this.expander);
|
|
146
|
+
target = settings.clickableNodeNames === true ? this.treeCell : this.expander;
|
|
147
|
+
|
|
148
|
+
target.off("click.treetable").on("click.treetable", handler);
|
|
149
|
+
target.off("keydown.treetable").on("keydown.treetable", function(e) {
|
|
150
|
+
if (e.keyCode == 13) {
|
|
151
|
+
handler.apply(this, [e]);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.indenter[0].style.paddingLeft = "" + (this.level() * settings.indent) + "px";
|
|
157
|
+
|
|
158
|
+
return this;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
Node.prototype.reveal = function() {
|
|
162
|
+
if (this.parentId != null) {
|
|
163
|
+
this.parentNode().reveal();
|
|
164
|
+
}
|
|
165
|
+
return this.expand();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
Node.prototype.setParent = function(node) {
|
|
169
|
+
if (this.parentId != null) {
|
|
170
|
+
this.tree[this.parentId].removeChild(this);
|
|
171
|
+
}
|
|
172
|
+
this.parentId = node.id;
|
|
173
|
+
this.row.data(this.settings.parentIdAttr, node.id);
|
|
174
|
+
return node.addChild(this);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
Node.prototype.show = function() {
|
|
178
|
+
if (!this.initialized) {
|
|
179
|
+
this._initialize();
|
|
180
|
+
}
|
|
181
|
+
this.row.show();
|
|
182
|
+
if (this.expanded()) {
|
|
183
|
+
this._showChildren();
|
|
184
|
+
}
|
|
185
|
+
return this;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
Node.prototype.toggle = function() {
|
|
189
|
+
if (this.expanded()) {
|
|
190
|
+
this.collapse();
|
|
191
|
+
} else {
|
|
192
|
+
this.expand();
|
|
193
|
+
}
|
|
194
|
+
return this;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
Node.prototype._hideChildren = function() {
|
|
198
|
+
var child, _i, _len, _ref, _results;
|
|
199
|
+
_ref = this.children;
|
|
200
|
+
_results = [];
|
|
201
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
202
|
+
child = _ref[_i];
|
|
203
|
+
_results.push(child.hide());
|
|
204
|
+
}
|
|
205
|
+
return _results;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
Node.prototype._initialize = function() {
|
|
209
|
+
var settings = this.settings;
|
|
210
|
+
|
|
211
|
+
this.render();
|
|
212
|
+
|
|
213
|
+
if (settings.expandable === true && settings.initialState === "collapsed") {
|
|
214
|
+
this.collapse();
|
|
215
|
+
} else {
|
|
216
|
+
this.expand();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (settings.onNodeInitialized != null) {
|
|
220
|
+
settings.onNodeInitialized.apply(this);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return this.initialized = true;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
Node.prototype._showChildren = function() {
|
|
227
|
+
var child, _i, _len, _ref, _results;
|
|
228
|
+
_ref = this.children;
|
|
229
|
+
_results = [];
|
|
230
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
231
|
+
child = _ref[_i];
|
|
232
|
+
_results.push(child.show());
|
|
233
|
+
}
|
|
234
|
+
return _results;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
return Node;
|
|
238
|
+
})();
|
|
239
|
+
|
|
240
|
+
Tree = (function() {
|
|
241
|
+
function Tree(table, settings) {
|
|
242
|
+
this.table = table;
|
|
243
|
+
this.settings = settings;
|
|
244
|
+
this.tree = {};
|
|
245
|
+
|
|
246
|
+
// Cache the nodes and roots in simple arrays for quick access/iteration
|
|
247
|
+
this.nodes = [];
|
|
248
|
+
this.roots = [];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
Tree.prototype.collapseAll = function() {
|
|
252
|
+
var node, _i, _len, _ref, _results;
|
|
253
|
+
_ref = this.nodes;
|
|
254
|
+
_results = [];
|
|
255
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
256
|
+
node = _ref[_i];
|
|
257
|
+
_results.push(node.collapse());
|
|
258
|
+
}
|
|
259
|
+
return _results;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
Tree.prototype.expandAll = function() {
|
|
263
|
+
var node, _i, _len, _ref, _results;
|
|
264
|
+
_ref = this.nodes;
|
|
265
|
+
_results = [];
|
|
266
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
267
|
+
node = _ref[_i];
|
|
268
|
+
_results.push(node.expand());
|
|
269
|
+
}
|
|
270
|
+
return _results;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
Tree.prototype.findLastNode = function (node) {
|
|
274
|
+
if (node.children.length > 0) {
|
|
275
|
+
return this.findLastNode(node.children[node.children.length - 1]);
|
|
276
|
+
} else {
|
|
277
|
+
return node;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
Tree.prototype.loadRows = function(rows) {
|
|
282
|
+
var node, row, i;
|
|
283
|
+
|
|
284
|
+
if (rows != null) {
|
|
285
|
+
for (i = 0; i < rows.length; i++) {
|
|
286
|
+
row = $(rows[i]);
|
|
287
|
+
|
|
288
|
+
if (row.data(this.settings.nodeIdAttr) != null) {
|
|
289
|
+
node = new Node(row, this.tree, this.settings);
|
|
290
|
+
this.nodes.push(node);
|
|
291
|
+
this.tree[node.id] = node;
|
|
292
|
+
|
|
293
|
+
if (node.parentId != null && this.tree[node.parentId]) {
|
|
294
|
+
this.tree[node.parentId].addChild(node);
|
|
295
|
+
} else {
|
|
296
|
+
this.roots.push(node);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
for (i = 0; i < this.nodes.length; i++) {
|
|
303
|
+
node = this.nodes[i].updateBranchLeafClass();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return this;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
Tree.prototype.move = function(node, destination) {
|
|
310
|
+
// Conditions:
|
|
311
|
+
// 1: +node+ should not be inserted as a child of +node+ itself.
|
|
312
|
+
// 2: +destination+ should not be the same as +node+'s current parent (this
|
|
313
|
+
// prevents +node+ from being moved to the same location where it already
|
|
314
|
+
// is).
|
|
315
|
+
// 3: +node+ should not be inserted in a location in a branch if this would
|
|
316
|
+
// result in +node+ being an ancestor of itself.
|
|
317
|
+
var nodeParent = node.parentNode();
|
|
318
|
+
if (node !== destination && destination.id !== node.parentId && $.inArray(node, destination.ancestors()) === -1) {
|
|
319
|
+
node.setParent(destination);
|
|
320
|
+
this._moveRows(node, destination);
|
|
321
|
+
|
|
322
|
+
// Re-render parentNode if this is its first child node, and therefore
|
|
323
|
+
// doesn't have the expander yet.
|
|
324
|
+
if (node.parentNode().children.length === 1) {
|
|
325
|
+
node.parentNode().render();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if(nodeParent){
|
|
330
|
+
nodeParent.updateBranchLeafClass();
|
|
331
|
+
}
|
|
332
|
+
if(node.parentNode()){
|
|
333
|
+
node.parentNode().updateBranchLeafClass();
|
|
334
|
+
}
|
|
335
|
+
node.updateBranchLeafClass();
|
|
336
|
+
return this;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
Tree.prototype.removeNode = function(node) {
|
|
340
|
+
// Recursively remove all descendants of +node+
|
|
341
|
+
this.unloadBranch(node);
|
|
342
|
+
|
|
343
|
+
// Remove node from DOM (<tr>)
|
|
344
|
+
node.row.remove();
|
|
345
|
+
|
|
346
|
+
// Remove node from parent children list
|
|
347
|
+
if (node.parentId != null) {
|
|
348
|
+
node.parentNode().removeChild(node);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Clean up Tree object (so Node objects are GC-ed)
|
|
352
|
+
delete this.tree[node.id];
|
|
353
|
+
this.nodes.splice($.inArray(node, this.nodes), 1);
|
|
354
|
+
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
Tree.prototype.render = function() {
|
|
359
|
+
var root, _i, _len, _ref;
|
|
360
|
+
_ref = this.roots;
|
|
361
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
362
|
+
root = _ref[_i];
|
|
363
|
+
|
|
364
|
+
// Naming is confusing (show/render). I do not call render on node from
|
|
365
|
+
// here.
|
|
366
|
+
root.show();
|
|
367
|
+
}
|
|
368
|
+
return this;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
Tree.prototype.sortBranch = function(node, sortFun) {
|
|
372
|
+
// First sort internal array of children
|
|
373
|
+
node.children.sort(sortFun);
|
|
374
|
+
|
|
375
|
+
// Next render rows in correct order on page
|
|
376
|
+
this._sortChildRows(node);
|
|
377
|
+
|
|
378
|
+
return this;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
Tree.prototype.unloadBranch = function(node) {
|
|
382
|
+
// Use a copy of the children array to not have other functions interfere
|
|
383
|
+
// with this function if they manipulate the children array
|
|
384
|
+
// (eg removeNode).
|
|
385
|
+
var children = node.children.slice(0),
|
|
386
|
+
i;
|
|
387
|
+
|
|
388
|
+
for (i = 0; i < children.length; i++) {
|
|
389
|
+
this.removeNode(children[i]);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Reset node's collection of children
|
|
393
|
+
node.children = [];
|
|
394
|
+
|
|
395
|
+
node.updateBranchLeafClass();
|
|
396
|
+
|
|
397
|
+
return this;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
Tree.prototype._moveRows = function(node, destination) {
|
|
401
|
+
var children = node.children, i;
|
|
402
|
+
|
|
403
|
+
node.row.insertAfter(destination.row);
|
|
404
|
+
node.render();
|
|
405
|
+
|
|
406
|
+
// Loop backwards through children to have them end up on UI in correct
|
|
407
|
+
// order (see #112)
|
|
408
|
+
for (i = children.length - 1; i >= 0; i--) {
|
|
409
|
+
this._moveRows(children[i], node);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// Special _moveRows case, move children to itself to force sorting
|
|
414
|
+
Tree.prototype._sortChildRows = function(parentNode) {
|
|
415
|
+
return this._moveRows(parentNode, parentNode);
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
return Tree;
|
|
419
|
+
})();
|
|
420
|
+
|
|
421
|
+
// jQuery Plugin
|
|
422
|
+
methods = {
|
|
423
|
+
init: function(options, force) {
|
|
424
|
+
var settings;
|
|
425
|
+
|
|
426
|
+
settings = $.extend({
|
|
427
|
+
branchAttr: "ttBranch",
|
|
428
|
+
clickableNodeNames: false,
|
|
429
|
+
column: 0,
|
|
430
|
+
columnElType: "td", // i.e. 'td', 'th' or 'td,th'
|
|
431
|
+
expandable: false,
|
|
432
|
+
expanderTemplate: "<a href='#'> </a>",
|
|
433
|
+
indent: 19,
|
|
434
|
+
indenterTemplate: "<span class='indenter'></span>",
|
|
435
|
+
initialState: "collapsed",
|
|
436
|
+
nodeIdAttr: "ttId", // maps to data-tt-id
|
|
437
|
+
parentIdAttr: "ttParentId", // maps to data-tt-parent-id
|
|
438
|
+
stringExpand: "Expand",
|
|
439
|
+
stringCollapse: "Collapse",
|
|
440
|
+
|
|
441
|
+
// Events
|
|
442
|
+
onInitialized: null,
|
|
443
|
+
onNodeCollapse: null,
|
|
444
|
+
onNodeExpand: null,
|
|
445
|
+
onNodeInitialized: null
|
|
446
|
+
}, options);
|
|
447
|
+
|
|
448
|
+
return this.each(function() {
|
|
449
|
+
var el = $(this), tree;
|
|
450
|
+
|
|
451
|
+
if (force || el.data("treetable") === undefined) {
|
|
452
|
+
tree = new Tree(this, settings);
|
|
453
|
+
tree.loadRows(this.rows).render();
|
|
454
|
+
|
|
455
|
+
el.addClass("treetable").data("treetable", tree);
|
|
456
|
+
|
|
457
|
+
if (settings.onInitialized != null) {
|
|
458
|
+
settings.onInitialized.apply(tree);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return el;
|
|
463
|
+
});
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
destroy: function() {
|
|
467
|
+
return this.each(function() {
|
|
468
|
+
return $(this).removeData("treetable").removeClass("treetable");
|
|
469
|
+
});
|
|
470
|
+
},
|
|
471
|
+
|
|
472
|
+
collapseAll: function() {
|
|
473
|
+
this.data("treetable").collapseAll();
|
|
474
|
+
return this;
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
collapseNode: function(id) {
|
|
478
|
+
var node = this.data("treetable").tree[id];
|
|
479
|
+
|
|
480
|
+
if (node) {
|
|
481
|
+
node.collapse();
|
|
482
|
+
} else {
|
|
483
|
+
throw new Error("Unknown node '" + id + "'");
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return this;
|
|
487
|
+
},
|
|
488
|
+
|
|
489
|
+
expandAll: function() {
|
|
490
|
+
this.data("treetable").expandAll();
|
|
491
|
+
return this;
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
expandNode: function(id) {
|
|
495
|
+
var node = this.data("treetable").tree[id];
|
|
496
|
+
|
|
497
|
+
if (node) {
|
|
498
|
+
if (!node.initialized) {
|
|
499
|
+
node._initialize();
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
node.expand();
|
|
503
|
+
} else {
|
|
504
|
+
throw new Error("Unknown node '" + id + "'");
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return this;
|
|
508
|
+
},
|
|
509
|
+
|
|
510
|
+
loadBranch: function(node, rows) {
|
|
511
|
+
var settings = this.data("treetable").settings,
|
|
512
|
+
tree = this.data("treetable").tree;
|
|
513
|
+
|
|
514
|
+
// TODO Switch to $.parseHTML
|
|
515
|
+
rows = $(rows);
|
|
516
|
+
|
|
517
|
+
if (node == null) { // Inserting new root nodes
|
|
518
|
+
this.append(rows);
|
|
519
|
+
} else {
|
|
520
|
+
var lastNode = this.data("treetable").findLastNode(node);
|
|
521
|
+
rows.insertAfter(lastNode.row);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
this.data("treetable").loadRows(rows);
|
|
525
|
+
|
|
526
|
+
// Make sure nodes are properly initialized
|
|
527
|
+
rows.filter("tr").each(function() {
|
|
528
|
+
tree[$(this).data(settings.nodeIdAttr)].show();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
if (node != null) {
|
|
532
|
+
// Re-render parent to ensure expander icon is shown (#79)
|
|
533
|
+
node.render().expand();
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return this;
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
move: function(nodeId, destinationId) {
|
|
540
|
+
var destination, node;
|
|
541
|
+
|
|
542
|
+
node = this.data("treetable").tree[nodeId];
|
|
543
|
+
destination = this.data("treetable").tree[destinationId];
|
|
544
|
+
this.data("treetable").move(node, destination);
|
|
545
|
+
|
|
546
|
+
return this;
|
|
547
|
+
},
|
|
548
|
+
|
|
549
|
+
node: function(id) {
|
|
550
|
+
return this.data("treetable").tree[id];
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
removeNode: function(id) {
|
|
554
|
+
var node = this.data("treetable").tree[id];
|
|
555
|
+
|
|
556
|
+
if (node) {
|
|
557
|
+
this.data("treetable").removeNode(node);
|
|
558
|
+
} else {
|
|
559
|
+
throw new Error("Unknown node '" + id + "'");
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return this;
|
|
563
|
+
},
|
|
564
|
+
|
|
565
|
+
reveal: function(id) {
|
|
566
|
+
var node = this.data("treetable").tree[id];
|
|
567
|
+
|
|
568
|
+
if (node) {
|
|
569
|
+
node.reveal();
|
|
570
|
+
} else {
|
|
571
|
+
throw new Error("Unknown node '" + id + "'");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return this;
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
sortBranch: function(node, columnOrFunction) {
|
|
578
|
+
var settings = this.data("treetable").settings,
|
|
579
|
+
prepValue,
|
|
580
|
+
sortFun;
|
|
581
|
+
|
|
582
|
+
columnOrFunction = columnOrFunction || settings.column;
|
|
583
|
+
sortFun = columnOrFunction;
|
|
584
|
+
|
|
585
|
+
if ($.isNumeric(columnOrFunction)) {
|
|
586
|
+
sortFun = function(a, b) {
|
|
587
|
+
var extractValue, valA, valB;
|
|
588
|
+
|
|
589
|
+
extractValue = function(node) {
|
|
590
|
+
var val = node.row.find("td:eq(" + columnOrFunction + ")").text();
|
|
591
|
+
// Ignore trailing/leading whitespace and use uppercase values for
|
|
592
|
+
// case insensitive ordering
|
|
593
|
+
return $.trim(val).toUpperCase();
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
valA = extractValue(a);
|
|
597
|
+
valB = extractValue(b);
|
|
598
|
+
|
|
599
|
+
if (valA < valB) return -1;
|
|
600
|
+
if (valA > valB) return 1;
|
|
601
|
+
return 0;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
this.data("treetable").sortBranch(node, sortFun);
|
|
606
|
+
return this;
|
|
607
|
+
},
|
|
608
|
+
|
|
609
|
+
unloadBranch: function(node) {
|
|
610
|
+
this.data("treetable").unloadBranch(node);
|
|
611
|
+
return this;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
$.fn.treetable = function(method) {
|
|
616
|
+
if (methods[method]) {
|
|
617
|
+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
|
618
|
+
} else if (typeof method === 'object' || !method) {
|
|
619
|
+
return methods.init.apply(this, arguments);
|
|
620
|
+
} else {
|
|
621
|
+
return $.error("Method " + method + " does not exist on jQuery.treetable");
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// Expose classes to world
|
|
626
|
+
this.TreeTable || (this.TreeTable = {});
|
|
627
|
+
this.TreeTable.Node = Node;
|
|
628
|
+
this.TreeTable.Tree = Tree;
|
|
629
|
+
})(jQuery);
|