merb-admin 0.8.1 → 0.8.3

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.
Files changed (109) hide show
  1. data/.gitignore +29 -27
  2. data/Gemfile +24 -22
  3. data/Gemfile.lock +86 -0
  4. data/LICENSE +20 -20
  5. data/README.rdoc +54 -58
  6. data/Rakefile +11 -44
  7. data/app/controllers/application.rb +6 -6
  8. data/app/controllers/main.rb +191 -191
  9. data/app/helpers/application_helper.rb +64 -64
  10. data/app/helpers/main_helper.rb +167 -167
  11. data/app/models/.gitkeep +0 -0
  12. data/app/views/layout/_message.html.erb +10 -10
  13. data/app/views/layout/dashboard.html.erb +34 -34
  14. data/app/views/layout/form.html.erb +48 -48
  15. data/app/views/layout/list.html.erb +42 -42
  16. data/app/views/main/_belongs_to.html.erb +29 -29
  17. data/app/views/main/_big_decimal.html.erb +12 -12
  18. data/app/views/main/_boolean.html.erb +7 -7
  19. data/app/views/main/_date.html.erb +12 -12
  20. data/app/views/main/_datetime.html.erb +12 -12
  21. data/app/views/main/_float.html.erb +12 -12
  22. data/app/views/main/_has_many.html.erb +16 -16
  23. data/app/views/main/_has_one.html.erb +30 -30
  24. data/app/views/main/_integer.html.erb +12 -12
  25. data/app/views/main/_properties.html.erb +18 -18
  26. data/app/views/main/_string.html.erb +15 -15
  27. data/app/views/main/_text.html.erb +11 -11
  28. data/app/views/main/_time.html.erb +12 -12
  29. data/app/views/main/_timestamp.html.erb +12 -12
  30. data/app/views/main/delete.html.erb +28 -28
  31. data/app/views/main/edit.html.erb +19 -19
  32. data/app/views/main/index.html.erb +22 -22
  33. data/app/views/main/list.html.erb +93 -93
  34. data/app/views/main/new.html.erb +16 -16
  35. data/config/init.rb +30 -0
  36. data/config/router.rb +4 -0
  37. data/lib/abstract_model.rb +84 -86
  38. data/lib/active_record_support.rb +147 -147
  39. data/lib/datamapper_support.rb +139 -140
  40. data/lib/generic_support.rb +13 -13
  41. data/lib/merb-admin.rb +99 -99
  42. data/lib/merb-admin/merbtasks.rb +103 -103
  43. data/lib/merb-admin/slicetasks.rb +174 -174
  44. data/lib/merb-admin/spectasks.rb +55 -55
  45. data/lib/merb-admin/version.rb +3 -0
  46. data/lib/sequel_support.rb +275 -275
  47. data/merb-admin.gemspec +42 -232
  48. data/public/javascripts/CollapsedFieldsets.js +85 -85
  49. data/public/javascripts/DateTimeShortcuts.js +255 -255
  50. data/public/javascripts/RelatedObjectLookups.js +96 -96
  51. data/public/javascripts/SelectBox.js +111 -111
  52. data/public/javascripts/SelectFilter2.js +113 -113
  53. data/public/javascripts/actions.js +39 -39
  54. data/public/javascripts/calendar.js +143 -143
  55. data/public/javascripts/core.js +176 -176
  56. data/public/javascripts/dateparse.js +233 -233
  57. data/public/javascripts/getElementsBySelector.js +167 -167
  58. data/public/javascripts/i18n.js +33 -33
  59. data/public/javascripts/ordering.js +137 -137
  60. data/public/javascripts/timeparse.js +94 -94
  61. data/public/javascripts/urlify.js +140 -140
  62. data/public/stylesheets/base.css +746 -746
  63. data/public/stylesheets/changelists.css +269 -269
  64. data/public/stylesheets/dashboard.css +24 -24
  65. data/public/stylesheets/forms.css +327 -327
  66. data/public/stylesheets/global.css +142 -142
  67. data/public/stylesheets/ie.css +50 -50
  68. data/public/stylesheets/layout.css +29 -29
  69. data/public/stylesheets/login.css +54 -54
  70. data/public/stylesheets/master.css +1 -1
  71. data/public/stylesheets/patch-iewin.css +7 -7
  72. data/public/stylesheets/rtl.css +206 -206
  73. data/public/stylesheets/widgets.css +506 -506
  74. data/screenshots/create.png +0 -0
  75. data/screenshots/delete.png +0 -0
  76. data/screenshots/edit.png +0 -0
  77. data/screenshots/index.png +0 -0
  78. data/screenshots/list.png +0 -0
  79. data/screenshots/new.png +0 -0
  80. data/spec/controllers/main_spec.rb +25 -25
  81. data/spec/migrations/activerecord/001_create_divisions_migration.rb +13 -13
  82. data/spec/migrations/activerecord/002_create_drafts_migration.rb +19 -19
  83. data/spec/migrations/activerecord/003_create_leagues_migration.rb +12 -12
  84. data/spec/migrations/activerecord/004_create_players_migration.rb +19 -20
  85. data/spec/migrations/activerecord/005_create_teams_migration.rb +22 -22
  86. data/spec/migrations/sequel/001_create_divisions_migration.rb +15 -15
  87. data/spec/migrations/sequel/002_create_drafts_migration.rb +21 -21
  88. data/spec/migrations/sequel/003_create_leagues_migration.rb +14 -14
  89. data/spec/migrations/sequel/004_create_players_migration.rb +21 -22
  90. data/spec/migrations/sequel/005_create_teams_migration.rb +24 -24
  91. data/spec/models/activerecord/division.rb +7 -7
  92. data/spec/models/activerecord/draft.rb +11 -11
  93. data/spec/models/activerecord/league.rb +6 -6
  94. data/spec/models/activerecord/player.rb +8 -8
  95. data/spec/models/activerecord/team.rb +13 -13
  96. data/spec/models/datamapper/division.rb +12 -12
  97. data/spec/models/datamapper/draft.rb +18 -18
  98. data/spec/models/datamapper/league.rb +11 -11
  99. data/spec/models/datamapper/player.rb +20 -21
  100. data/spec/models/datamapper/team.rb +22 -22
  101. data/spec/models/sequel/division.rb +15 -15
  102. data/spec/models/sequel/draft.rb +19 -19
  103. data/spec/models/sequel/league.rb +14 -14
  104. data/spec/models/sequel/player.rb +18 -18
  105. data/spec/models/sequel/team.rb +21 -21
  106. data/spec/requests/main_spec.rb +763 -763
  107. data/spec/spec_helper.rb +113 -112
  108. metadata +247 -41
  109. data/VERSION +0 -1
@@ -1,167 +1,167 @@
1
- /* document.getElementsBySelector(selector)
2
- - returns an array of element objects from the current document
3
- matching the CSS selector. Selectors can contain element names,
4
- class names and ids and can be nested. For example:
5
-
6
- elements = document.getElementsBySelect('div#main p a.external')
7
-
8
- Will return an array of all 'a' elements with 'external' in their
9
- class attribute that are contained inside 'p' elements that are
10
- contained inside the 'div' element which has id="main"
11
-
12
- New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
13
- See http://www.w3.org/TR/css3-selectors/#attribute-selectors
14
-
15
- Version 0.4 - Simon Willison, March 25th 2003
16
- -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
17
- -- Opera 7 fails
18
- */
19
-
20
- function getAllChildren(e) {
21
- // Returns all children of element. Workaround required for IE5/Windows. Ugh.
22
- return e.all ? e.all : e.getElementsByTagName('*');
23
- }
24
-
25
- document.getElementsBySelector = function(selector) {
26
- // Attempt to fail gracefully in lesser browsers
27
- if (!document.getElementsByTagName) {
28
- return new Array();
29
- }
30
- // Split selector in to tokens
31
- var tokens = selector.split(' ');
32
- var currentContext = new Array(document);
33
- for (var i = 0; i < tokens.length; i++) {
34
- token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
35
- if (token.indexOf('#') > -1) {
36
- // Token is an ID selector
37
- var bits = token.split('#');
38
- var tagName = bits[0];
39
- var id = bits[1];
40
- var element = document.getElementById(id);
41
- if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) {
42
- // ID not found or tag with that ID not found, return false.
43
- return new Array();
44
- }
45
- // Set currentContext to contain just this element
46
- currentContext = new Array(element);
47
- continue; // Skip to next token
48
- }
49
- if (token.indexOf('.') > -1) {
50
- // Token contains a class selector
51
- var bits = token.split('.');
52
- var tagName = bits[0];
53
- var className = bits[1];
54
- if (!tagName) {
55
- tagName = '*';
56
- }
57
- // Get elements matching tag, filter them for class selector
58
- var found = new Array;
59
- var foundCount = 0;
60
- for (var h = 0; h < currentContext.length; h++) {
61
- var elements;
62
- if (tagName == '*') {
63
- elements = getAllChildren(currentContext[h]);
64
- } else {
65
- try {
66
- elements = currentContext[h].getElementsByTagName(tagName);
67
- }
68
- catch(e) {
69
- elements = [];
70
- }
71
- }
72
- for (var j = 0; j < elements.length; j++) {
73
- found[foundCount++] = elements[j];
74
- }
75
- }
76
- currentContext = new Array;
77
- var currentContextIndex = 0;
78
- for (var k = 0; k < found.length; k++) {
79
- if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
80
- currentContext[currentContextIndex++] = found[k];
81
- }
82
- }
83
- continue; // Skip to next token
84
- }
85
- // Code to deal with attribute selectors
86
- if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
87
- var tagName = RegExp.$1;
88
- var attrName = RegExp.$2;
89
- var attrOperator = RegExp.$3;
90
- var attrValue = RegExp.$4;
91
- if (!tagName) {
92
- tagName = '*';
93
- }
94
- // Grab all of the tagName elements within current context
95
- var found = new Array;
96
- var foundCount = 0;
97
- for (var h = 0; h < currentContext.length; h++) {
98
- var elements;
99
- if (tagName == '*') {
100
- elements = getAllChildren(currentContext[h]);
101
- } else {
102
- elements = currentContext[h].getElementsByTagName(tagName);
103
- }
104
- for (var j = 0; j < elements.length; j++) {
105
- found[foundCount++] = elements[j];
106
- }
107
- }
108
- currentContext = new Array;
109
- var currentContextIndex = 0;
110
- var checkFunction; // This function will be used to filter the elements
111
- switch (attrOperator) {
112
- case '=': // Equality
113
- checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
114
- break;
115
- case '~': // Match one of space seperated words
116
- checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
117
- break;
118
- case '|': // Match start with value followed by optional hyphen
119
- checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
120
- break;
121
- case '^': // Match starts with value
122
- checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
123
- break;
124
- case '$': // Match ends with value - fails with "Warning" in Opera 7
125
- checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
126
- break;
127
- case '*': // Match ends with value
128
- checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
129
- break;
130
- default :
131
- // Just test for existence of attribute
132
- checkFunction = function(e) { return e.getAttribute(attrName); };
133
- }
134
- currentContext = new Array;
135
- var currentContextIndex = 0;
136
- for (var k = 0; k < found.length; k++) {
137
- if (checkFunction(found[k])) {
138
- currentContext[currentContextIndex++] = found[k];
139
- }
140
- }
141
- // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
142
- continue; // Skip to next token
143
- }
144
- // If we get here, token is JUST an element (not a class or ID selector)
145
- tagName = token;
146
- var found = new Array;
147
- var foundCount = 0;
148
- for (var h = 0; h < currentContext.length; h++) {
149
- var elements = currentContext[h].getElementsByTagName(tagName);
150
- for (var j = 0; j < elements.length; j++) {
151
- found[foundCount++] = elements[j];
152
- }
153
- }
154
- currentContext = found;
155
- }
156
- return currentContext;
157
- }
158
-
159
- /* That revolting regular expression explained
160
- /^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
161
- \---/ \---/\-------------/ \-------/
162
- | | | |
163
- | | | The value
164
- | | ~,|,^,$,* or =
165
- | Attribute
166
- Tag
167
- */
1
+ /* document.getElementsBySelector(selector)
2
+ - returns an array of element objects from the current document
3
+ matching the CSS selector. Selectors can contain element names,
4
+ class names and ids and can be nested. For example:
5
+
6
+ elements = document.getElementsBySelect('div#main p a.external')
7
+
8
+ Will return an array of all 'a' elements with 'external' in their
9
+ class attribute that are contained inside 'p' elements that are
10
+ contained inside the 'div' element which has id="main"
11
+
12
+ New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
13
+ See http://www.w3.org/TR/css3-selectors/#attribute-selectors
14
+
15
+ Version 0.4 - Simon Willison, March 25th 2003
16
+ -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
17
+ -- Opera 7 fails
18
+ */
19
+
20
+ function getAllChildren(e) {
21
+ // Returns all children of element. Workaround required for IE5/Windows. Ugh.
22
+ return e.all ? e.all : e.getElementsByTagName('*');
23
+ }
24
+
25
+ document.getElementsBySelector = function(selector) {
26
+ // Attempt to fail gracefully in lesser browsers
27
+ if (!document.getElementsByTagName) {
28
+ return new Array();
29
+ }
30
+ // Split selector in to tokens
31
+ var tokens = selector.split(' ');
32
+ var currentContext = new Array(document);
33
+ for (var i = 0; i < tokens.length; i++) {
34
+ token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
35
+ if (token.indexOf('#') > -1) {
36
+ // Token is an ID selector
37
+ var bits = token.split('#');
38
+ var tagName = bits[0];
39
+ var id = bits[1];
40
+ var element = document.getElementById(id);
41
+ if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) {
42
+ // ID not found or tag with that ID not found, return false.
43
+ return new Array();
44
+ }
45
+ // Set currentContext to contain just this element
46
+ currentContext = new Array(element);
47
+ continue; // Skip to next token
48
+ }
49
+ if (token.indexOf('.') > -1) {
50
+ // Token contains a class selector
51
+ var bits = token.split('.');
52
+ var tagName = bits[0];
53
+ var className = bits[1];
54
+ if (!tagName) {
55
+ tagName = '*';
56
+ }
57
+ // Get elements matching tag, filter them for class selector
58
+ var found = new Array;
59
+ var foundCount = 0;
60
+ for (var h = 0; h < currentContext.length; h++) {
61
+ var elements;
62
+ if (tagName == '*') {
63
+ elements = getAllChildren(currentContext[h]);
64
+ } else {
65
+ try {
66
+ elements = currentContext[h].getElementsByTagName(tagName);
67
+ }
68
+ catch(e) {
69
+ elements = [];
70
+ }
71
+ }
72
+ for (var j = 0; j < elements.length; j++) {
73
+ found[foundCount++] = elements[j];
74
+ }
75
+ }
76
+ currentContext = new Array;
77
+ var currentContextIndex = 0;
78
+ for (var k = 0; k < found.length; k++) {
79
+ if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
80
+ currentContext[currentContextIndex++] = found[k];
81
+ }
82
+ }
83
+ continue; // Skip to next token
84
+ }
85
+ // Code to deal with attribute selectors
86
+ if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
87
+ var tagName = RegExp.$1;
88
+ var attrName = RegExp.$2;
89
+ var attrOperator = RegExp.$3;
90
+ var attrValue = RegExp.$4;
91
+ if (!tagName) {
92
+ tagName = '*';
93
+ }
94
+ // Grab all of the tagName elements within current context
95
+ var found = new Array;
96
+ var foundCount = 0;
97
+ for (var h = 0; h < currentContext.length; h++) {
98
+ var elements;
99
+ if (tagName == '*') {
100
+ elements = getAllChildren(currentContext[h]);
101
+ } else {
102
+ elements = currentContext[h].getElementsByTagName(tagName);
103
+ }
104
+ for (var j = 0; j < elements.length; j++) {
105
+ found[foundCount++] = elements[j];
106
+ }
107
+ }
108
+ currentContext = new Array;
109
+ var currentContextIndex = 0;
110
+ var checkFunction; // This function will be used to filter the elements
111
+ switch (attrOperator) {
112
+ case '=': // Equality
113
+ checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
114
+ break;
115
+ case '~': // Match one of space seperated words
116
+ checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
117
+ break;
118
+ case '|': // Match start with value followed by optional hyphen
119
+ checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
120
+ break;
121
+ case '^': // Match starts with value
122
+ checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
123
+ break;
124
+ case '$': // Match ends with value - fails with "Warning" in Opera 7
125
+ checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
126
+ break;
127
+ case '*': // Match ends with value
128
+ checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
129
+ break;
130
+ default :
131
+ // Just test for existence of attribute
132
+ checkFunction = function(e) { return e.getAttribute(attrName); };
133
+ }
134
+ currentContext = new Array;
135
+ var currentContextIndex = 0;
136
+ for (var k = 0; k < found.length; k++) {
137
+ if (checkFunction(found[k])) {
138
+ currentContext[currentContextIndex++] = found[k];
139
+ }
140
+ }
141
+ // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
142
+ continue; // Skip to next token
143
+ }
144
+ // If we get here, token is JUST an element (not a class or ID selector)
145
+ tagName = token;
146
+ var found = new Array;
147
+ var foundCount = 0;
148
+ for (var h = 0; h < currentContext.length; h++) {
149
+ var elements = currentContext[h].getElementsByTagName(tagName);
150
+ for (var j = 0; j < elements.length; j++) {
151
+ found[foundCount++] = elements[j];
152
+ }
153
+ }
154
+ currentContext = found;
155
+ }
156
+ return currentContext;
157
+ }
158
+
159
+ /* That revolting regular expression explained
160
+ /^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
161
+ \---/ \---/\-------------/ \-------/
162
+ | | | |
163
+ | | | The value
164
+ | | ~,|,^,$,* or =
165
+ | Attribute
166
+ Tag
167
+ */
@@ -1,33 +1,33 @@
1
- /* gettext library */
2
-
3
- var catalog = new Array();
4
-
5
- function pluralidx(count) { return (count == 1) ? 0 : 1; }
6
-
7
- function gettext(msgid) {
8
- var value = catalog[msgid];
9
- if (typeof(value) == 'undefined') {
10
- return msgid;
11
- } else {
12
- return (typeof(value) == 'string') ? value : value[0];
13
- }
14
- }
15
-
16
- function ngettext(singular, plural, count) {
17
- value = catalog[singular];
18
- if (typeof(value) == 'undefined') {
19
- return (count == 1) ? singular : plural;
20
- } else {
21
- return value[pluralidx(count)];
22
- }
23
- }
24
-
25
- function gettext_noop(msgid) { return msgid; }
26
-
27
- function interpolate(fmt, obj, named) {
28
- if (named) {
29
- return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
30
- } else {
31
- return fmt.replace(/%s/g, function(match){return String(obj.shift())});
32
- }
33
- }
1
+ /* gettext library */
2
+
3
+ var catalog = new Array();
4
+
5
+ function pluralidx(count) { return (count == 1) ? 0 : 1; }
6
+
7
+ function gettext(msgid) {
8
+ var value = catalog[msgid];
9
+ if (typeof(value) == 'undefined') {
10
+ return msgid;
11
+ } else {
12
+ return (typeof(value) == 'string') ? value : value[0];
13
+ }
14
+ }
15
+
16
+ function ngettext(singular, plural, count) {
17
+ value = catalog[singular];
18
+ if (typeof(value) == 'undefined') {
19
+ return (count == 1) ? singular : plural;
20
+ } else {
21
+ return value[pluralidx(count)];
22
+ }
23
+ }
24
+
25
+ function gettext_noop(msgid) { return msgid; }
26
+
27
+ function interpolate(fmt, obj, named) {
28
+ if (named) {
29
+ return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
30
+ } else {
31
+ return fmt.replace(/%s/g, function(match){return String(obj.shift())});
32
+ }
33
+ }
@@ -1,137 +1,137 @@
1
- addEvent(window, 'load', reorder_init);
2
-
3
- var lis;
4
- var top = 0;
5
- var left = 0;
6
- var height = 30;
7
-
8
- function reorder_init() {
9
- lis = document.getElementsBySelector('ul#orderthese li');
10
- var input = document.getElementsBySelector('input[name=order_]')[0];
11
- setOrder(input.value.split(','));
12
- input.disabled = true;
13
- draw();
14
- // Now initialise the dragging behaviour
15
- var limit = (lis.length - 1) * height;
16
- for (var i = 0; i < lis.length; i++) {
17
- var li = lis[i];
18
- var img = document.getElementById('handle'+li.id);
19
- li.style.zIndex = 1;
20
- Drag.init(img, li, left + 10, left + 10, top + 10, top + 10 + limit);
21
- li.onDragStart = startDrag;
22
- li.onDragEnd = endDrag;
23
- img.style.cursor = 'move';
24
- }
25
- }
26
-
27
- function submitOrderForm() {
28
- var inputOrder = document.getElementsBySelector('input[name=order_]')[0];
29
- inputOrder.value = getOrder();
30
- inputOrder.disabled=false;
31
- }
32
-
33
- function startDrag() {
34
- this.style.zIndex = '10';
35
- this.className = 'dragging';
36
- }
37
-
38
- function endDrag(x, y) {
39
- this.style.zIndex = '1';
40
- this.className = '';
41
- // Work out how far along it has been dropped, using x co-ordinate
42
- var oldIndex = this.index;
43
- var newIndex = Math.round((y - 10 - top) / height);
44
- // 'Snap' to the correct position
45
- this.style.top = (10 + top + newIndex * height) + 'px';
46
- this.index = newIndex;
47
- moveItem(oldIndex, newIndex);
48
- }
49
-
50
- function moveItem(oldIndex, newIndex) {
51
- // Swaps two items, adjusts the index and left co-ord for all others
52
- if (oldIndex == newIndex) {
53
- return; // Nothing to swap;
54
- }
55
- var direction, lo, hi;
56
- if (newIndex > oldIndex) {
57
- lo = oldIndex;
58
- hi = newIndex;
59
- direction = -1;
60
- } else {
61
- direction = 1;
62
- hi = oldIndex;
63
- lo = newIndex;
64
- }
65
- var lis2 = new Array(); // We will build the new order in this array
66
- for (var i = 0; i < lis.length; i++) {
67
- if (i < lo || i > hi) {
68
- // Position of items not between the indexes is unaffected
69
- lis2[i] = lis[i];
70
- continue;
71
- } else if (i == newIndex) {
72
- lis2[i] = lis[oldIndex];
73
- continue;
74
- } else {
75
- // Item is between the two indexes - move it along 1
76
- lis2[i] = lis[i - direction];
77
- }
78
- }
79
- // Re-index everything
80
- reIndex(lis2);
81
- lis = lis2;
82
- draw();
83
- // document.getElementById('hiddenOrder').value = getOrder();
84
- document.getElementsBySelector('input[name=order_]')[0].value = getOrder();
85
- }
86
-
87
- function reIndex(lis) {
88
- for (var i = 0; i < lis.length; i++) {
89
- lis[i].index = i;
90
- }
91
- }
92
-
93
- function draw() {
94
- for (var i = 0; i < lis.length; i++) {
95
- var li = lis[i];
96
- li.index = i;
97
- li.style.position = 'absolute';
98
- li.style.left = (10 + left) + 'px';
99
- li.style.top = (10 + top + (i * height)) + 'px';
100
- }
101
- }
102
-
103
- function getOrder() {
104
- var order = new Array(lis.length);
105
- for (var i = 0; i < lis.length; i++) {
106
- order[i] = lis[i].id.substring(1, 100);
107
- }
108
- return order.join(',');
109
- }
110
-
111
- function setOrder(id_list) {
112
- /* Set the current order to match the lsit of IDs */
113
- var temp_lis = new Array();
114
- for (var i = 0; i < id_list.length; i++) {
115
- var id = 'p' + id_list[i];
116
- temp_lis[temp_lis.length] = document.getElementById(id);
117
- }
118
- reIndex(temp_lis);
119
- lis = temp_lis;
120
- draw();
121
- }
122
-
123
- function addEvent(elm, evType, fn, useCapture)
124
- // addEvent and removeEvent
125
- // cross-browser event handling for IE5+, NS6 and Mozilla
126
- // By Scott Andrew
127
- {
128
- if (elm.addEventListener){
129
- elm.addEventListener(evType, fn, useCapture);
130
- return true;
131
- } else if (elm.attachEvent){
132
- var r = elm.attachEvent("on"+evType, fn);
133
- return r;
134
- } else {
135
- elm['on'+evType] = fn;
136
- }
137
- }
1
+ addEvent(window, 'load', reorder_init);
2
+
3
+ var lis;
4
+ var top = 0;
5
+ var left = 0;
6
+ var height = 30;
7
+
8
+ function reorder_init() {
9
+ lis = document.getElementsBySelector('ul#orderthese li');
10
+ var input = document.getElementsBySelector('input[name=order_]')[0];
11
+ setOrder(input.value.split(','));
12
+ input.disabled = true;
13
+ draw();
14
+ // Now initialise the dragging behaviour
15
+ var limit = (lis.length - 1) * height;
16
+ for (var i = 0; i < lis.length; i++) {
17
+ var li = lis[i];
18
+ var img = document.getElementById('handle'+li.id);
19
+ li.style.zIndex = 1;
20
+ Drag.init(img, li, left + 10, left + 10, top + 10, top + 10 + limit);
21
+ li.onDragStart = startDrag;
22
+ li.onDragEnd = endDrag;
23
+ img.style.cursor = 'move';
24
+ }
25
+ }
26
+
27
+ function submitOrderForm() {
28
+ var inputOrder = document.getElementsBySelector('input[name=order_]')[0];
29
+ inputOrder.value = getOrder();
30
+ inputOrder.disabled=false;
31
+ }
32
+
33
+ function startDrag() {
34
+ this.style.zIndex = '10';
35
+ this.className = 'dragging';
36
+ }
37
+
38
+ function endDrag(x, y) {
39
+ this.style.zIndex = '1';
40
+ this.className = '';
41
+ // Work out how far along it has been dropped, using x co-ordinate
42
+ var oldIndex = this.index;
43
+ var newIndex = Math.round((y - 10 - top) / height);
44
+ // 'Snap' to the correct position
45
+ this.style.top = (10 + top + newIndex * height) + 'px';
46
+ this.index = newIndex;
47
+ moveItem(oldIndex, newIndex);
48
+ }
49
+
50
+ function moveItem(oldIndex, newIndex) {
51
+ // Swaps two items, adjusts the index and left co-ord for all others
52
+ if (oldIndex == newIndex) {
53
+ return; // Nothing to swap;
54
+ }
55
+ var direction, lo, hi;
56
+ if (newIndex > oldIndex) {
57
+ lo = oldIndex;
58
+ hi = newIndex;
59
+ direction = -1;
60
+ } else {
61
+ direction = 1;
62
+ hi = oldIndex;
63
+ lo = newIndex;
64
+ }
65
+ var lis2 = new Array(); // We will build the new order in this array
66
+ for (var i = 0; i < lis.length; i++) {
67
+ if (i < lo || i > hi) {
68
+ // Position of items not between the indexes is unaffected
69
+ lis2[i] = lis[i];
70
+ continue;
71
+ } else if (i == newIndex) {
72
+ lis2[i] = lis[oldIndex];
73
+ continue;
74
+ } else {
75
+ // Item is between the two indexes - move it along 1
76
+ lis2[i] = lis[i - direction];
77
+ }
78
+ }
79
+ // Re-index everything
80
+ reIndex(lis2);
81
+ lis = lis2;
82
+ draw();
83
+ // document.getElementById('hiddenOrder').value = getOrder();
84
+ document.getElementsBySelector('input[name=order_]')[0].value = getOrder();
85
+ }
86
+
87
+ function reIndex(lis) {
88
+ for (var i = 0; i < lis.length; i++) {
89
+ lis[i].index = i;
90
+ }
91
+ }
92
+
93
+ function draw() {
94
+ for (var i = 0; i < lis.length; i++) {
95
+ var li = lis[i];
96
+ li.index = i;
97
+ li.style.position = 'absolute';
98
+ li.style.left = (10 + left) + 'px';
99
+ li.style.top = (10 + top + (i * height)) + 'px';
100
+ }
101
+ }
102
+
103
+ function getOrder() {
104
+ var order = new Array(lis.length);
105
+ for (var i = 0; i < lis.length; i++) {
106
+ order[i] = lis[i].id.substring(1, 100);
107
+ }
108
+ return order.join(',');
109
+ }
110
+
111
+ function setOrder(id_list) {
112
+ /* Set the current order to match the lsit of IDs */
113
+ var temp_lis = new Array();
114
+ for (var i = 0; i < id_list.length; i++) {
115
+ var id = 'p' + id_list[i];
116
+ temp_lis[temp_lis.length] = document.getElementById(id);
117
+ }
118
+ reIndex(temp_lis);
119
+ lis = temp_lis;
120
+ draw();
121
+ }
122
+
123
+ function addEvent(elm, evType, fn, useCapture)
124
+ // addEvent and removeEvent
125
+ // cross-browser event handling for IE5+, NS6 and Mozilla
126
+ // By Scott Andrew
127
+ {
128
+ if (elm.addEventListener){
129
+ elm.addEventListener(evType, fn, useCapture);
130
+ return true;
131
+ } else if (elm.attachEvent){
132
+ var r = elm.attachEvent("on"+evType, fn);
133
+ return r;
134
+ } else {
135
+ elm['on'+evType] = fn;
136
+ }
137
+ }