locomotive_cms 0.0.4.beta5 → 0.0.4.beta7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. data/Gemfile +12 -10
  2. data/app/controllers/admin/api_contents_controller.rb +10 -1
  3. data/app/controllers/admin/base_controller.rb +2 -2
  4. data/app/controllers/admin/cross_domain_sessions_controller.rb +7 -4
  5. data/app/controllers/admin/current_sites_controller.rb +2 -0
  6. data/app/controllers/admin/imports_controller.rb +8 -27
  7. data/app/controllers/admin/installation_controller.rb +79 -0
  8. data/app/controllers/admin/passwords_controller.rb +2 -2
  9. data/app/controllers/admin/sessions_controller.rb +2 -2
  10. data/app/controllers/admin/sites_controller.rb +2 -0
  11. data/app/controllers/application_controller.rb +1 -1
  12. data/app/helpers/admin/assets_helper.rb +0 -6
  13. data/app/helpers/admin/{login_helper.rb → box_helper.rb} +7 -3
  14. data/app/helpers/admin/custom_fields_helper.rb +2 -2
  15. data/app/models/asset_collection.rb +10 -0
  16. data/app/models/content_instance.rb +19 -0
  17. data/app/models/content_type.rb +20 -2
  18. data/app/models/extensions/page/tree.rb +4 -6
  19. data/app/models/site.rb +11 -3
  20. data/app/uploaders/theme_asset_uploader.rb +1 -1
  21. data/app/views/admin/asset_collections/edit.html.haml +2 -2
  22. data/app/views/admin/asset_collections/new.html.haml +1 -1
  23. data/app/views/admin/assets/_form.html.haml +2 -2
  24. data/app/views/admin/content_types/_form.html.haml +2 -2
  25. data/app/views/admin/content_types/new.html.haml +1 -1
  26. data/app/views/admin/contents/_form.html.haml +2 -2
  27. data/app/views/admin/contents/index.html.haml +1 -1
  28. data/app/views/admin/cross_domain_sessions/new.html.haml +1 -1
  29. data/app/views/admin/current_sites/_form.html.haml +3 -3
  30. data/app/views/admin/current_sites/edit.html.haml +1 -1
  31. data/app/views/admin/errors/no_page.html.haml +1 -0
  32. data/app/views/admin/errors/no_site.html.haml +1 -0
  33. data/app/views/admin/imports/new.html.haml +11 -0
  34. data/app/views/admin/imports/show.html.haml +1 -1
  35. data/app/views/admin/installation/step_1.html.haml +24 -0
  36. data/app/views/admin/installation/step_2.html.haml +26 -0
  37. data/app/views/admin/installation/step_3.html.haml +23 -0
  38. data/app/views/{layouts/admin → admin/layouts}/application.html.haml +0 -0
  39. data/app/views/admin/layouts/box.html.haml +21 -0
  40. data/app/views/admin/layouts/error.html.haml +1 -0
  41. data/app/views/admin/my_accounts/edit.html.haml +1 -1
  42. data/app/views/admin/pages/_form.html.haml +2 -3
  43. data/app/views/admin/pages/index.html.haml +1 -1
  44. data/app/views/admin/passwords/edit.html.haml +2 -2
  45. data/app/views/admin/passwords/new.html.haml +2 -2
  46. data/app/views/admin/sessions/new.html.haml +2 -2
  47. data/app/views/admin/shared/_head.html.haml +4 -5
  48. data/app/views/admin/sites/_form.html.haml +3 -3
  49. data/app/views/admin/snippets/_form.html.haml +2 -2
  50. data/app/views/admin/theme_assets/_form.html.haml +2 -2
  51. data/app/views/admin/theme_assets/index.html.haml +1 -1
  52. data/config/application.rb +1 -3
  53. data/config/assets.yml +94 -0
  54. data/config/environments/development.rb +0 -5
  55. data/config/environments/production.rb +1 -3
  56. data/config/environments/test.rb +1 -5
  57. data/config/initializers/carrierwave.rb +17 -0
  58. data/config/initializers/locomotive.rb +12 -0
  59. data/config/locales/admin_ui_en.yml +33 -1
  60. data/config/locales/admin_ui_fr.yml +34 -1
  61. data/config/locales/flash.en.yml +1 -0
  62. data/config/locales/flash.fr.yml +1 -0
  63. data/config/mongoid.yml +2 -2
  64. data/config/routes.rb +6 -1
  65. data/lib/generators/locomotive/install/install_generator.rb +18 -10
  66. data/lib/generators/locomotive/install/templates/README +23 -13
  67. data/lib/generators/locomotive/install/templates/locomotive.rb +13 -1
  68. data/lib/locomotive/carrierwave.rb +1 -0
  69. data/lib/locomotive/configuration.rb +3 -1
  70. data/lib/locomotive/custom_fields.rb +0 -1
  71. data/lib/locomotive/engine.rb +12 -9
  72. data/lib/locomotive/import/asset_collections.rb +40 -8
  73. data/lib/locomotive/import/assets.rb +20 -12
  74. data/lib/locomotive/import/base.rb +46 -0
  75. data/lib/locomotive/import/content_types.rb +51 -15
  76. data/lib/locomotive/import/job.rb +59 -15
  77. data/lib/locomotive/import/logger.rb +13 -0
  78. data/lib/locomotive/import/pages.rb +64 -25
  79. data/lib/locomotive/import/site.rb +3 -5
  80. data/lib/locomotive/import/snippets.rb +6 -8
  81. data/lib/locomotive/import.rb +2 -0
  82. data/lib/locomotive/liquid/drops/asset_collections.rb +4 -4
  83. data/lib/locomotive/liquid/drops/contents.rb +21 -16
  84. data/lib/locomotive/liquid/filters/html.rb +9 -6
  85. data/lib/locomotive/liquid/tags/nav.rb +18 -5
  86. data/lib/locomotive/liquid/tags/paginate.rb +3 -3
  87. data/lib/locomotive/misc_form_builder.rb +2 -7
  88. data/lib/locomotive/render.rb +9 -3
  89. data/lib/locomotive/routing/site_dispatcher.rb +8 -6
  90. data/lib/locomotive/version.rb +1 -1
  91. data/public/images/admin/box/buttons/right_bg.png +0 -0
  92. data/public/javascripts/admin/aloha/VERSION.txt +1 -1
  93. data/public/javascripts/admin/aloha/aloha-nodeps.js +140 -101
  94. data/public/javascripts/admin/aloha/aloha.js +193 -105
  95. data/public/javascripts/admin/aloha/css/aloha.css +65 -4
  96. data/public/javascripts/admin/aloha/deps/prettyPhoto/resources/css/prettyPhoto.css +2 -2
  97. data/public/javascripts/admin/aloha/i18n/de.dict +2 -0
  98. data/public/javascripts/admin/aloha/i18n/en.dict +2 -0
  99. data/public/javascripts/admin/aloha/i18n/pl.dict +5 -0
  100. data/public/javascripts/admin/aloha/images/base.png +0 -0
  101. data/public/javascripts/admin/aloha/images/base_big.png +0 -0
  102. data/public/javascripts/admin/aloha/images/base_multi.png +0 -0
  103. data/public/javascripts/admin/aloha/images/fade_in.png +0 -0
  104. data/public/javascripts/admin/aloha/images/fade_out.png +0 -0
  105. data/public/javascripts/admin/aloha/images/gentics_logo.png +0 -0
  106. data/public/javascripts/admin/aloha/images/grabhandle.png +0 -0
  107. data/public/javascripts/admin/aloha/images/maximize.png +0 -0
  108. data/public/javascripts/admin/aloha/images/pin.png +0 -0
  109. data/public/javascripts/admin/aloha/images/removeformat.png +0 -0
  110. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/examples/triSports.css +86 -0
  111. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/examples/triSports.html +44 -0
  112. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/de.dict +4 -0
  113. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/en.dict +4 -0
  114. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/fr.dict +4 -0
  115. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/plugin.js +1 -0
  116. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/product.js +1 -0
  117. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/2xu-wetsuit.jpg +0 -0
  118. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/asics-noosa.jpg +0 -0
  119. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/fivefingers-kso.jpg +0 -0
  120. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/kuota-kueen-k.jpg +0 -0
  121. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/mizuno-wave-musha2.jpg +0 -0
  122. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/product.css +69 -0
  123. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/product_button.gif +0 -0
  124. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/simplon-mrt.jpg +0 -0
  125. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/trek-fuel-ex.jpg +0 -0
  126. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/trisports.jpg +0 -0
  127. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/zoggs-predator.jpg +0 -0
  128. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/de.dict +0 -0
  129. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/en.dict +0 -0
  130. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/fi.dict +0 -0
  131. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/fr.dict +0 -0
  132. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/it.dict +0 -0
  133. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/plugin.js +0 -0
  134. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/examples/AlohaAbbr.css +48 -0
  135. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/examples/AlohaAbbr.html +69 -0
  136. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/i18n/de.dict +4 -0
  137. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/i18n/en.dict +4 -0
  138. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/plugin.js +7 -0
  139. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/i18n/pl.dict +30 -0
  140. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js +1 -1
  141. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.HighlightEditables/plugin.js +1 -1
  142. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/LinkList.js +7 -0
  143. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/delicious.js +7 -0
  144. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/i18n/pl.dict +4 -0
  145. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/plugin.js +1 -1
  146. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/css/LinkChecker.css +14 -0
  147. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/examples/AlohaLinkChecker.css +49 -0
  148. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/examples/AlohaLinkChecker.html +82 -0
  149. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/i18n/en.dict +27 -0
  150. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/plugin.js +7 -0
  151. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/proxy.php +235 -0
  152. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.List/plugin.js +1 -1
  153. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Paste/plugin.js +7 -0
  154. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Paste/wordpastehandler.js +7 -0
  155. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/i18n/de.dict +1 -0
  156. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/i18n/en.dict +1 -0
  157. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/plugin.js +1 -1
  158. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/de.dict +2 -0
  159. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/en.dict +2 -0
  160. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/pl.dict +12 -0
  161. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/plugin.js +1 -1
  162. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/table.css +28 -110
  163. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/wai_green.png +0 -0
  164. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/wai_red.png +0 -0
  165. data/public/javascripts/admin/asset_collections.js +11 -7
  166. data/public/javascripts/admin/contents.js +3 -1
  167. data/public/javascripts/admin/site.js +9 -3
  168. data/public/javascripts/admin/snippets.js +1 -1
  169. data/public/stylesheets/admin/box.css +5 -0
  170. data/public/stylesheets/admin/formtastic_changes.css +5 -1
  171. data/public/stylesheets/admin/inline_editor.css +22 -5
  172. data/public/stylesheets/admin/installation.css +50 -0
  173. data/public/stylesheets/admin/layout.css +9 -0
  174. metadata +176 -127
  175. data/app/controllers/home_controller.rb +0 -7
  176. data/app/views/admin/snippets/index.html.haml +0 -15
  177. data/app/views/home/show.html.haml +0 -4
  178. data/app/views/layouts/admin/box.html.haml +0 -19
  179. data/app/views/layouts/application.html.haml +0 -7
  180. data/lib/generators/locomotive/copy_assets/copy_assets_generator.rb +0 -14
  181. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/de.dict +0 -2
  182. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/en.dict +0 -2
  183. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/eo.dict +0 -2
  184. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/fi.dict +0 -2
  185. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/fr.dict +0 -2
  186. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/it.dict +0 -2
  187. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/plugin.js +0 -7
  188. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/de.dict +0 -20
  189. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/en.dict +0 -20
  190. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/eo.dict +0 -16
  191. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/fi.dict +0 -20
  192. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/fr.dict +0 -16
  193. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/it.dict +0 -20
  194. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/plugin.js +0 -7
  195. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/css/jquery.autocomplete.css +0 -48
  196. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/deps/jquery.autocomplete.js +0 -1
  197. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressource.js +0 -7
  198. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressourcedummy.js +0 -7
  199. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressourceregistry.js +0 -7
  200. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Loader/plugin.js +0 -1
  201. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/en.dict +0 -2
  202. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/fi.dict +0 -2
  203. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/fr.dict +0 -2
  204. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/person.css +0 -3
  205. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/plugin.js +0 -1
  206. data/public/javascripts/admin/aloha/plugins/simpletable/plugin.js.deactivated +0 -2330
@@ -1,2330 +0,0 @@
1
- /**
2
- * Gentics Aloha Simple Table Plugin
3
- *
4
- * !!! PROOF OF CONCEPT !!!
5
- *
6
- */
7
- /**
8
- * Register the SimpleTablePlugin as GENTICS.Aloha.Plugin
9
- */
10
- GENTICS.Aloha.SimpleTablePlugin = new GENTICS.Aloha.Plugin('com.gentics.aloha.plugins.SimpleTable', 'table');
11
-
12
- //
13
- //
14
- // I M P O R T A N T
15
- //
16
- // if you want to disable ff table resize handles this has to be executed onload
17
- //
18
- // document.execCommand( 'enableInlineTableEditing', false, false );
19
- //
20
- // the call will fail if used outside of onload, and has to be surrounded by try/catch
21
- // but it's proven to work!
22
- //
23
- //
24
-
25
-
26
- /* -- ATTRIBUTES -- */
27
- /**
28
- * The Create-Layer Object of the SimpleTablePlugin
29
- *
30
- * @see GENTICS.Aloha.Table.CreateLayer
31
- */
32
- GENTICS.Aloha.SimpleTablePlugin.createLayer = undefined;
33
-
34
- /**
35
- * Configure the available languages
36
- */
37
- GENTICS.Aloha.SimpleTablePlugin.languages = ['en', 'de'];
38
-
39
- /**
40
- * An Array which holds all newly created tables contains DOM-Nodes of
41
- * table-objects
42
- */
43
- GENTICS.Aloha.SimpleTablePlugin.TableRegistry = new Array();
44
-
45
- /**
46
- * Holds the active table-object
47
- */
48
- GENTICS.Aloha.SimpleTablePlugin.activeTable = undefined;
49
-
50
- /**
51
- * parameters-objects for tables
52
- *
53
- * @param className
54
- * The class of activated tables
55
- */
56
- GENTICS.Aloha.SimpleTablePlugin.parameters = {
57
- className : 'GENTICS_Aloha_SimpleTable', // class of editable tables
58
- classSelectionRow : 'GENTICS_Aloha_SimpleTable_selectColumn', // class for the upper table-row to select columns
59
- classSelectionColumn : 'GENTICS_Aloha_SimpleTable_selectRow', // class for the left bound table-cells to select rows
60
- classLeftUpperCorner : 'GENTICS_Aloha_SimpleTable_leftUpperCorner', // class for the left upper corner cell
61
- classTableWrapper : 'GENTICS_Aloha_SimpleTable_wrapper', // class of the outest table-wrapping div
62
- classCellSelected : 'GENTICS_Aloha_Cell_selected', // class of cell which are selected (row/column selection)
63
- selectionArea : 10 // width/height of the selection rows (in pixel)
64
- };
65
-
66
- /**
67
- * The configuration-object for the implementer of the plugin. All keys of the
68
- * "parameters" object could be overwritten within this object and will simply
69
- * be used instead.
70
- */
71
- GENTICS.Aloha.SimpleTablePlugin.config = new Object();
72
- /* -- END ATTRIBUTES -- */
73
-
74
- /* -- METHODS -- */
75
- /**
76
- * Init method of the Table-plugin transforms all tables in the document and
77
- * sets the initialized flag to true
78
- *
79
- * @return void
80
- */
81
- GENTICS.Aloha.SimpleTablePlugin.init = function() {
82
-
83
- // disable this plugin
84
- return;
85
-
86
- // add reference to the create layer object
87
- this.createLayer = new GENTICS.Aloha.Table.CreateLayer();
88
-
89
- var that = this;
90
-
91
- // subscribe for the 'editableActivated' event to activate all tables in the editable
92
- GENTICS.Aloha.EventRegistry.subscribe(GENTICS.Aloha, 'editableCreated', function(event, editable) {
93
- // add a mousedown event to all created editables to check if
94
- editable.obj.bind('mousedown', function(jqEvent) {
95
- GENTICS.Aloha.SimpleTablePlugin.setFocusedTable(undefined);
96
- if (!editable.floatingMenu.isActive) {
97
- editable.floatingMenu.call();
98
- }
99
- });
100
-
101
- editable.obj.find('table').each(function() {
102
- // instantiate a new table-object
103
- var table = new GENTICS.Aloha.Table(this);
104
-
105
- table.parentEditable = editable;
106
-
107
- // activate the table
108
- table.activate();
109
-
110
- // add the activated table to the TableRegistry
111
- GENTICS.Aloha.SimpleTablePlugin.TableRegistry.push(table);
112
- });
113
- });
114
-
115
- // call initButtons when event enableCreated is triggered
116
- GENTICS.Aloha.EventRegistry.subscribe(GENTICS.Aloha, 'editableCreated', this.initCreateTableButton);
117
-
118
- // disable advanced table handles in firefox
119
- // try/catch since opera won't like this
120
- $(document).ready(function () {
121
- // document.execCommand( 'enableInlineTableEditing', false, false );
122
- });
123
-
124
- this.initialized = true;
125
- };
126
-
127
-
128
- /**
129
- * initialize the buttons and register them on floating menu
130
- * @param event event object
131
- * @param editable current editable object
132
- */
133
- GENTICS.Aloha.SimpleTablePlugin.initCreateTableButton = function (event, editable) {
134
-
135
- var buttons = new Array();
136
-
137
- var sep = new GENTICS.Aloha.OldFloatingMenu.Button({
138
- name : 'separator',
139
- title : 'Separator',
140
- cssClass : 'GENTICS_separator',
141
- onClick : function(){}
142
- });
143
-
144
- buttons.push(sep);
145
-
146
- var table = new GENTICS.Aloha.OldFloatingMenu.Button({
147
- name : 'table',
148
- status : 'released',
149
- title : 'Insert table',
150
- cssClass : 'GENTICS_button_table',
151
- onClick : function() {
152
- GENTICS.Aloha.SimpleTablePlugin.createDialog(this.html.children("a.GENTICS_button_table").get(0));
153
- }
154
- });
155
-
156
- buttons.push(table);
157
-
158
- editable.floatingMenu.registerButtons(GENTICS.Aloha.SimpleTablePlugin, buttons);
159
- };
160
-
161
- /**
162
- * This function adds the createDialog to the calling element
163
- *
164
- * @param callingElement
165
- * The element, which was clicked. It's needed to set the right
166
- * position to the create-table-dialog.
167
- */
168
- GENTICS.Aloha.SimpleTablePlugin.createDialog = function(callingElement) {
169
- // set the calling element to the layer the calling element mostly will be
170
- // the element which was clicked on it is used to position the createLayer
171
- this.createLayer.set('target', callingElement);
172
-
173
- // show the createLayer
174
- this.createLayer.show();
175
-
176
- };
177
-
178
- /**
179
- * Creates a normal html-table, "activates" this table and inserts it into the
180
- * active Editable
181
- *
182
- * @param cols
183
- * number of colums for the created table
184
- * @param cols
185
- * number of rows for the created table
186
- * @return void
187
- */
188
- GENTICS.Aloha.SimpleTablePlugin.createTable = function(cols, rows) {
189
- // Check if there is an active Editable and that it contains an element (= .obj)
190
- if (GENTICS.Aloha.activeEditable != null && typeof GENTICS.Aloha.activeEditable.obj != 'undefined') {
191
- // create a dom-table object
192
- var table = document.createElement('table');
193
- var tableId = table.id = GENTICS.Aloha.TableHelper.getNewTableID();
194
- var tbody = document.createElement('tbody');
195
-
196
- // create "rows"-number of rows
197
- for (var i = 0; i < rows; i++) {
198
- var tr = document.createElement('tr');
199
- // create "cols"-number of columns
200
- for (var j = 0; j < cols; j++) {
201
- var text = document.createTextNode('\u00a0');
202
- var td = document.createElement('td');
203
- td.appendChild(text);
204
- tr.appendChild(td);
205
- }
206
- tbody.appendChild(tr);
207
- }
208
- table.appendChild(tbody);
209
-
210
- // insert at current cursor position
211
- this.insertAtCursorPos(table);
212
-
213
- // if the table is inserted
214
- var tableReloadedFromDOM = document.getElementById(tableId);
215
-
216
- var tableObj = new GENTICS.Aloha.Table(tableReloadedFromDOM);
217
-
218
- tableObj.parentEditable = GENTICS.Aloha.activeEditable;
219
-
220
- // transform the table to be editable
221
- // tableObj.activate();
222
-
223
- // after creating the table, trigger a click into the first cell to
224
- // focus the content
225
- // for IE set a timeout of 10ms to focus the first cell, other wise it
226
- // won't work
227
- // if (jQuery.browser.msie) {
228
- // window.setTimeout(function() { tableObj.cells[0].wrapper.get(0).focus(); }, 20);
229
- // } else {
230
- // tableObj.cells[0].wrapper.get(0).focus();
231
- // }
232
-
233
- GENTICS.Aloha.SimpleTablePlugin.TableRegistry.push(tableObj);
234
-
235
- // no active editable => error
236
- } else {
237
- this.error('There is no active Editable where the table can be inserted!');
238
- }
239
- };
240
-
241
- /**
242
- * Inserts the given element at the cursor position of the current active Editable
243
- *
244
- * @param elementThe element which should be inserted (a DOM-object)
245
- */
246
- GENTICS.Aloha.SimpleTablePlugin.insertAtCursorPos = function(element) {
247
- // check if the element-parameter is set
248
- if (typeof element != 'undefined') {
249
- // check if there is an active editable
250
- if (typeof GENTICS.Aloha.activeEditable.obj != 'undefined'){
251
- var range, html;
252
- // insertion for IE
253
- if (jQuery.browser.msie) {
254
- range = GENTICS.Aloha.Editable.range;
255
- html = (element.nodeType == 3) ? element.data : element.outerHTML;
256
- range.pasteHTML(html);
257
-
258
- // insertion for other browser
259
- } else if (window.getSelection && window.getSelection().getRangeAt){
260
- range = GENTICS.Aloha.Editable.range;
261
- range.insertNode(element);
262
-
263
- // insertion didn't work trigger ERROR to user!
264
- } else {
265
- this.error("Table couldn't be inserted");
266
- }
267
- }else{
268
- this.warn('No active Editable => do nothing.');
269
- }
270
- }else{
271
- this.error('This method didn\'t get an element to insert!');
272
- }
273
- };
274
-
275
- GENTICS.Aloha.SimpleTablePlugin.setFocusedTable = function(focusTable) {
276
- for (var i = 0; i < GENTICS.Aloha.SimpleTablePlugin.TableRegistry.length; i++) {
277
- GENTICS.Aloha.SimpleTablePlugin.TableRegistry[i].hasFocus = false;
278
- }
279
- if (typeof focusTable != 'undefined') {
280
- focusTable.hasFocus = true;
281
- }
282
- GENTICS.Aloha.SimpleTablePlugin.activeTable = focusTable;
283
- };
284
-
285
- /**
286
- * Calls the GENTICS.Aloha.log function with 'error' level
287
- *
288
- * @see GENTICS.Aloha.log
289
- * @param msg
290
- * The message to display
291
- * @return void
292
- */
293
- GENTICS.Aloha.SimpleTablePlugin.error = function(msg) {
294
- GENTICS.Aloha.Log.error(this, msg);
295
- };
296
-
297
- /**
298
- * Calls the GENTICS.Aloha.log function with 'debug' level
299
- *
300
- * @see GENTICS.Aloha.log
301
- * @param msg
302
- * The message to display
303
- * @return void
304
- */
305
- GENTICS.Aloha.SimpleTablePlugin.debug = function(msg) {
306
- GENTICS.Aloha.Log.debug(this, msg);
307
- };
308
-
309
- /**
310
- * Calls the GENTICS.Aloha.log function with 'info' level
311
- *
312
- * @see GENTICS.Aloha.log
313
- * @param msg
314
- * The message to display
315
- * @return void
316
- */
317
- GENTICS.Aloha.SimpleTablePlugin.info = function(msg) {
318
- GENTICS.Aloha.Log.info(this, msg);
319
- };
320
-
321
- /**
322
- * Calls the GENTICS.Aloha.log function with 'info' level
323
- *
324
- * @see GENTICS.Aloha.log
325
- * @param msg
326
- * The message to display
327
- * @return void
328
- */
329
- GENTICS.Aloha.SimpleTablePlugin.log = function(msg) {
330
- GENTICS.Aloha.log('log', this, msg);
331
- };
332
-
333
- /**
334
- * The "get"-method returns the value of the given key.
335
- * First it searches in the config for the property.
336
- * If there is no property with the given name in the
337
- * "config"-object it returns the entry associated with
338
- * in the parameters-object
339
- *
340
- * @param property
341
- * @return void
342
- *
343
- */
344
- GENTICS.Aloha.SimpleTablePlugin.get = function (property) {
345
- if (this.config[property]) {
346
- return this.config[property];
347
- }
348
- if (this.parameters[property]) {
349
- return this.parameters[property];
350
- }
351
- return undefined;
352
- };
353
-
354
- /**
355
- * The "set"-method takes a key and a value. It checks if there is a
356
- * key-value pair in the config-object. If so it saves the data in the
357
- * config-object. If not it saves the data in the parameters-object.
358
- *
359
- * @param key the key which should be set
360
- * @param value the value which should be set for the associated key
361
- */
362
- GENTICS.Aloha.SimpleTablePlugin.set = function (key, value) {
363
- if (this.config[key]) {
364
- this.config[key] = value;
365
- }else{
366
- this.parameters[key] = value;
367
- }
368
- };
369
-
370
- /**
371
- * Make the given jQuery object (representing an editable) clean for saving
372
- * Find all tables and deactivate them
373
- * @param obj jQuery object to make clean
374
- * @return void
375
- */
376
- GENTICS.Aloha.SimpleTablePlugin.makeClean = function (obj) {
377
- // find all table tags
378
- obj.find('table').each(function() {
379
- // instantiate a new table-object
380
- var table = new GENTICS.Aloha.Table(this);
381
-
382
- // deactivate the table
383
- table.deactivate();
384
- });
385
- };
386
-
387
- /**
388
- * String representation of the Table-object
389
- *
390
- * @return The plugins namespace (string)
391
- */
392
- GENTICS.Aloha.SimpleTablePlugin.toString = function() {
393
- return this.prefix;
394
- };
395
- /* -- END METHODS -- */
396
-
397
-
398
- /**************************
399
- +---------------------+
400
- | GENTICS.Aloha.Table |
401
- +---------------------+
402
- ***************************/
403
- /**
404
- * Constructor of the table object
405
- *
406
- * @param table
407
- * the dom-representation of the held table
408
- * @return void
409
- */
410
- GENTICS.Aloha.Table = function(table) {
411
- // set the table attribut "obj" as a jquery represenation of the dom-table
412
- this.obj = jQuery(table);
413
-
414
- // find the dimensions of the table
415
- var rows = this.obj.find("tr");
416
- var firstRow = jQuery(rows.get(0));
417
- this.numCols = firstRow.children("td, th").length;
418
- this.numRows = rows.length;
419
-
420
- // init the cell-attribute with an empty array
421
- this.cells = new Array();
422
-
423
- // iterate over table cells and create Cell-objects
424
- var rows = this.obj.find('tr');
425
- for (var i = 0; i < rows.length; i++) {
426
- var row = jQuery(rows[i]);
427
- var cols = row.children();
428
- for (var j = 0; j < cols.length; j++) {
429
- var col = cols[j];
430
- var Cell = new GENTICS.Aloha.Table.Cell(col, this);
431
- this.cells.push(Cell);
432
- }
433
- }
434
- };
435
- /* -- ATTRIBUTES -- */
436
- /**
437
- * Attribute holding the jQuery-table-represenation
438
- */
439
- GENTICS.Aloha.Table.prototype.obj = undefined;
440
-
441
- /**
442
- * The DOM-element of the outest div-container wrapped around the cell
443
- */
444
- GENTICS.Aloha.Table.prototype.tableWrapper = undefined;
445
-
446
- /**
447
- * An array of all Cells contained in the Table
448
- *
449
- * @see GENTICS.Aloha.Table.Cell
450
- */
451
- GENTICS.Aloha.Table.prototype.cells = undefined;
452
-
453
- /**
454
- * Number of rows of the table
455
- */
456
- GENTICS.Aloha.Table.prototype.numRows = undefined;
457
-
458
- /**
459
- * Number of rows of the table
460
- */
461
- GENTICS.Aloha.Table.prototype.numCols = undefined;
462
-
463
- /**
464
- * This attribute holds the floatingMenu of the table-object
465
- */
466
- GENTICS.Aloha.Table.prototype.floatingMenu = undefined;
467
-
468
- /**
469
- * Flag wether the table is active or not
470
- */
471
- GENTICS.Aloha.Table.prototype.isActive = false;
472
-
473
- /**
474
- * Flag wether the table is focused or not
475
- */
476
- GENTICS.Aloha.Table.prototype.hasFocus = false;
477
-
478
- /**
479
- * The editable which contains the table
480
- */
481
- GENTICS.Aloha.Table.prototype.parentEditable = undefined;
482
-
483
- /**
484
- * Flag to check if the mouse was pressed. For row- and column-selection.
485
- */
486
- GENTICS.Aloha.Table.prototype.mousedown = false;
487
-
488
- /**
489
- * ID of the column which was pressed when selecting columns
490
- */
491
- GENTICS.Aloha.Table.prototype.clickedColumnId = -1;
492
-
493
- /**
494
- * ID of the row which was pressed when selecting rows
495
- */
496
- GENTICS.Aloha.Table.prototype.clickedRowId = -1;
497
-
498
- /**
499
- * collection of columnindexes of the columns which should be selected
500
- */
501
- GENTICS.Aloha.Table.prototype.columnsToSelect = new Array();
502
-
503
- /**
504
- * collection of rowindexes of the rows which should be selected
505
- */
506
- GENTICS.Aloha.Table.prototype.rowsToSelect = new Array();
507
-
508
- /**
509
- * contains the plugin id used for interaction with the floating menu
510
- */
511
- GENTICS.Aloha.Table.prototype.fmPluginId = undefined;
512
-
513
- /* -- END ATTRIBUTES -- */
514
-
515
- /* -- METHODS -- */
516
- /**
517
- * Wrapper-Mehotd to return a property of GENTICS.Aloha.SimpleTablePlugin.get
518
- *
519
- * @see GENTICS.Aloha.SimpleTablePlugin.get
520
- * @param property
521
- * the property whichs value should be return
522
- * @return the value associated with the property
523
- */
524
- GENTICS.Aloha.Table.prototype.get = function(property) {
525
- return GENTICS.Aloha.SimpleTablePlugin.get(property);
526
- };
527
-
528
- /**
529
- * Wrapper-Method for GENTICS.Aloha.SimpleTablePlugin.set
530
- *
531
- * @see GENTICS.Aloha.SimpleTablePlugin.set
532
- * @param key
533
- * the key whichs value should be set
534
- * @param value
535
- * the value for the key
536
- * @return void
537
- */
538
- GENTICS.Aloha.Table.prototype.set = function(key, value) {
539
- GENTICS.Aloha.SimpleTablePlugin.set(key, value);
540
- };
541
-
542
- /**
543
- * Transforms the existing dom-table into an editable aloha-table. In fact it
544
- * replaces the td-elements with equivalent GENTICS.Aloha.Table.Cell-elements
545
- * with attached events.
546
- * Furthermore it creates wrapping divs to realize a click-area for row- and
547
- * column selection and also attaches events.
548
- *
549
- * @return void
550
- */
551
- GENTICS.Aloha.Table.prototype.activate = function() {
552
- if (this.isActive) {
553
- return;
554
- }
555
- var that = this;
556
-
557
- // alter the table attributes
558
- this.obj.addClass(this.get('className'));
559
-
560
- // set an id to the table if not already set
561
- if (this.obj.attr('id') == '') {
562
- this.obj.attr('id', GENTICS.Aloha.TableHelper.getNewTableID());
563
- }
564
-
565
- // add the floating menu to the table
566
- this.attachFloatingMenu();
567
-
568
- // this.obj.bind('keydown', function(jqEvent){
569
- // if (!jqEvent.ctrlKey && !jqEvent.shiftKey) {
570
- // if (GENTICS.Aloha.TableHelper.selectedCells.length > 0 && GENTICS.Aloha.TableHelper.selectedCells[0].length > 0) {
571
- // GENTICS.Aloha.TableHelper.selectedCells[0][0].firstChild.focus();
572
- // }
573
- // }
574
- // });
575
-
576
- // handle click event of the table
577
- this.obj.bind('click', function(e){
578
- // stop bubbling the event to the outer divs, a click in the table
579
- // should only be handled in the table
580
- e.stopPropagation();
581
- return false;
582
- });
583
-
584
- this.obj.bind('mousedown', function(jqEvent) {
585
- // focus the table if not already done
586
- if (!that.hasFocus) {
587
- that.focus();
588
- }
589
-
590
- // // if a mousedown is done on the table, just focus the first cell of the table
591
- // setTimeout(function() {
592
- // var firstCell = that.obj.find('tr:nth-child(2) td:nth-child(2)').children('div[contentEditable=true]').get(0);
593
- // GENTICS.Aloha.TableHelper.unselectCells();
594
- // jQuery(firstCell).get(0).focus();
595
- // }, 5);
596
-
597
- // stop bubbling and default-behaviour
598
- jqEvent.stopPropagation();
599
- jqEvent.preventDefault();
600
- return false;
601
- });
602
-
603
- // ### create a wrapper for the table (@see HINT below)
604
- // wrapping div for the table to suppress the display of the resize-controls of
605
- // the editable divs within the cells
606
- // var tableWrapper = jQuery('<div class="' + this.get('classTableWrapper') + '" contentEditable="false"></div>');
607
-
608
- // wrap the tableWrapper around the table
609
- // this.obj.wrap(tableWrapper);
610
-
611
- // :HINT The outest div (Editable) of the table is still in an editable
612
- // div. So IE will surround the the wrapper div with a resize-border
613
- // Workaround => just disable the handles so hopefully won't happen any ugly stuff.
614
- // Disable resize and selection of the controls (only IE)
615
- // Events only can be set to elements which are loaded from the DOM (if they
616
- // were created dynamically before) ;)
617
- // var htmlTableWrapper = this.obj.parents('.' + this.get('classTableWrapper'));
618
- // htmlTableWrapper.get(0).onresizestart = function(e) { return false; };
619
- // htmlTableWrapper.get(0).oncontrolselect = function(e) { return false; };
620
- //
621
- // this.tableWrapper = this.obj.parents('.' + this.get('classTableWrapper')).get(0);
622
-
623
- jQuery(this.cells).each(function () {
624
- this.activate();
625
- });
626
-
627
- // after the cells where replaced with contentEditables ... add selection cells
628
- // first add the additional columns on the left side
629
- // this.attachSelectionColumn();
630
- // // then add the additional row at the top
631
- // this.attachSelectionRow();
632
- //
633
- // // attach events for the last cell
634
- // this.attachLastCellEvents();
635
-
636
- // set flag, that the table is activated
637
- this.isActive = true;
638
-
639
- // this.lastCellLastCaretPos = 0;
640
-
641
- // handle cursor moves in first and last table cell
642
- // e.keyCode: left = 37, up = 38, right = 39, down = 40
643
- // this.obj.find('tr:nth-child(2) td:nth-child(2)').css('background', 'blue');
644
- // this.obj.find('tr:last td:last div.GENTICS_Table_Cell_editable').bind('keyup', function (e) {
645
- // GENTICS.Aloha.Log.debug(that, 'last caret pos: ' + that.lastCellLastCaretPos + ' new: '
646
- // + GENTICS.Aloha.Selection.rangeObject.endOffset);
647
- //
648
- // // bei den richtigen keys letze pos mit aktueller pos vergleichen
649
- // if (that.lastCellLastCaretPos == GENTICS.Aloha.Selection.rangeObject.endOffset
650
- // && (e.keyCode == 39 || e.keyCode == 40)) {
651
- // alert('jump out');
652
- // }
653
- //
654
- // that.lastCellLastCaretPos = GENTICS.Aloha.Selection.rangeObject.endOffset;
655
- // });
656
-
657
- // throw a new event when the table has been activated
658
- GENTICS.Aloha.EventRegistry.trigger(
659
- new GENTICS.Aloha.Event(
660
- 'tableActivated',
661
- GENTICS.Aloha,
662
- [ this ]
663
- )
664
- );
665
- };
666
-
667
- /**
668
- * Creates a new floatingMenu with the defined buttons and attaches it to the
669
- * Table-object
670
- *
671
- * @return void
672
- */
673
- GENTICS.Aloha.Table.prototype.attachFloatingMenu = function() {
674
- // create a floating menu for the table and set it as attribute
675
- this.floatingMenu = new GENTICS.Aloha.OldFloatingMenu(this.obj);
676
- this.fmPluginId = this + this.obj.attr('id');
677
-
678
- var that = this;
679
- // register the fm buttons
680
- var buttons = [
681
- // add column (left) button
682
- new GENTICS.Aloha.OldFloatingMenu.Button({
683
- name : 'addColumnLeft',
684
- title : 'Add column left',
685
- cssClass : 'GENTICS_Aloha_addColumnLeft',
686
- onClick : function(){
687
- that.addColumnsLeft();
688
- }
689
- }),
690
- // add column (right) button
691
- new GENTICS.Aloha.OldFloatingMenu.Button({
692
- name : 'addColumnRight',
693
- title : 'Add column right',
694
- cssClass : 'GENTICS_Aloha_addColumnRight',
695
- onClick : function(){
696
- that.addColumnsRight();
697
- }
698
- }),
699
- // insert row before button
700
- new GENTICS.Aloha.OldFloatingMenu.Button({
701
- name : 'addRowBefore',
702
- title : 'Insert row before',
703
- cssClass : 'GENTICS_Aloha_addRowBefore',
704
- onClick : function(){
705
- that.addRowsBefore(true);
706
- }
707
- }),
708
- // insert row after button
709
- new GENTICS.Aloha.OldFloatingMenu.Button({
710
- name : 'addRowAfter',
711
- title : 'Insert row after',
712
- cssClass : 'GENTICS_Aloha_addRowAfter',
713
- onClick : function(){
714
- that.addRowsAfter(true);
715
- }
716
- }),
717
- // delete selected rows
718
- new GENTICS.Aloha.OldFloatingMenu.Button({
719
- name : 'deleteRows',
720
- title : 'Delete selected row(s)',
721
- cssClass : 'GENTICS_Aloha_deleteRows',
722
- onClick : function(){
723
- var bool = window.confirm('You are going to delete the selected rows?\nContinue?');
724
- if (bool) {
725
- that.deleteRows();
726
- }
727
- }
728
- }),
729
- // delete selected columns
730
- new GENTICS.Aloha.OldFloatingMenu.Button({
731
- name : 'deleteColumns',
732
- title : 'Delete selected column(s)',
733
- cssClass : 'GENTICS_Aloha_deleteColumns',
734
- onClick : function(){
735
- var bool = window.confirm('You are going to delete the selected columns?\nContinue?');
736
- if (bool) {
737
- that.deleteColumns();
738
- }
739
- }
740
- })
741
- ];
742
-
743
- // register the buttons for the floating menu
744
- this.floatingMenu.registerButtons(this.fmPluginId, buttons);
745
-
746
- // hide the buttons for deleting rows and columns
747
- };
748
-
749
- /**
750
- * Add the selection-column to the left side of the table and attach the events
751
- * for selection rows
752
- *
753
- * @return void
754
- */
755
- GENTICS.Aloha.Table.prototype.attachSelectionColumn = function() {
756
- // create an empty cell
757
- var emptyCell = jQuery('<td>');
758
- // set the unicode '&nbsp;' code
759
- emptyCell.html('\u00a0');
760
-
761
- var that = this;
762
- var rows = this.obj.context.rows;
763
- // add a column before each first cell of each row
764
- for (var i = 0; i < rows.length; i++) {
765
- var rowObj = jQuery(rows[i]);
766
- var columnToInsert = emptyCell.clone();
767
- columnToInsert.addClass(this.get('classSelectionColumn'));
768
- columnToInsert.css('width', this.get('selectionArea') + 'px');
769
- rowObj.find('td:first').before(columnToInsert);
770
-
771
- // rowIndex + 1 because an addtional row is still added
772
- var rowIndex = i + 1;
773
-
774
- // this method sets the selection-events to the cell
775
- this.attachRowSelectionEventsToCell(columnToInsert);
776
- }
777
- };
778
-
779
- /**
780
- * Binds the needed selection-mouse events to the given cell
781
- *
782
- * @param cell
783
- * The jquery object of the table-data field
784
- * @return void
785
- */
786
- GENTICS.Aloha.Table.prototype.attachRowSelectionEventsToCell = function(cell){
787
- var that = this;
788
-
789
- // unbind eventually existing events of this cell
790
- cell.unbind('mousedown');
791
- cell.unbind('mouseover');
792
-
793
- // prevent ie from selecting the contents of the table
794
- cell.get(0).onselectstart = function() { return false; };
795
-
796
- cell.bind('mousedown', function(e){
797
- that.rowSelectionMouseDown(e);
798
-
799
- // focus the table (if not already done)
800
- that.focus();
801
-
802
- // stop bubble, otherwise the mousedown of the table is called ...
803
- e.stopPropagation();
804
-
805
- // prevent ff/chrome/safare from selecting the contents of the table
806
- //return false;
807
- });
808
-
809
- cell.bind('mouseover', function(e) { that.rowSelectionMouseOver(e); e.preventDefault(); });
810
- };
811
-
812
- /**
813
- * Mouse-Down event for the selection-cells on the left side of the table
814
- *
815
- * @param jqEvent
816
- * the jquery-event object
817
- * @return void
818
- */
819
- GENTICS.Aloha.Table.prototype.rowSelectionMouseDown = function (jqEvent) {
820
- // set flag that the mouse is pressed
821
- this.mousedown = true;
822
-
823
- // if no cells are selected, reset the selection-array
824
- if (GENTICS.Aloha.TableHelper.selectedCells.length == 0) {
825
- this.rowsToSelect = new Array();
826
- }
827
-
828
- // set the origin-rowId of the mouse-click
829
- this.clickedRowId = jqEvent.currentTarget.parentNode.rowIndex;
830
-
831
- // set the array of to-be-selected columns
832
- if (jqEvent.ctrlKey) {
833
- var arrayIndex = jQuery.inArray(this.clickedRowId, this.rowsToSelect);
834
- if (arrayIndex >= 0) {
835
- this.rowsToSelect.splice(arrayIndex, 1);
836
- }else{
837
- this.rowsToSelect.push(this.clickedRowId);
838
- }
839
- }else if (jqEvent.shiftKey) {
840
- this.rowsToSelect.sort(function(a,b){return a - b;});
841
- var start = this.rowsToSelect[0];
842
- var end = this.clickedRowId;
843
- if (start > end) {
844
- start = end;
845
- end = this.rowsToSelect[0];
846
- }
847
- this.rowsToSelect = new Array();
848
- for (var i = start; i <= end; i++) {
849
- this.rowsToSelect.push(i);
850
- }
851
- }else{
852
- this.rowsToSelect = [this.clickedRowId];
853
- }
854
-
855
- // do the selection
856
- this.selectRows();
857
-
858
- // prevent browser from selecting the table
859
- jqEvent.preventDefault();
860
- };
861
-
862
- /**
863
- * The mouse-over event for the selection-cells on the left side of the table.
864
- * On mouse-over check which column was clicked, calculate the span between
865
- * clicked and mouse-overed cell and mark them as selected
866
- *
867
- * @param jqEvent
868
- * the jquery-event object
869
- * @return void
870
- */
871
- GENTICS.Aloha.Table.prototype.rowSelectionMouseOver = function (jqEvent) {
872
- var rowIndex = jqEvent.currentTarget.parentNode.rowIndex;
873
-
874
- // only select the row if the mouse was clicked and the clickedRowId isn't
875
- // from the selection-row (row-id = 0)
876
- if (this.mousedown && this.clickedRowId >= 0) {
877
- var indexInArray = jQuery.inArray(rowIndex, this.rowsToSelect);
878
-
879
- var start = (rowIndex < this.clickedRowId) ? rowIndex : this.clickedRowId;
880
- var end = (rowIndex < this.clickedRowId) ? this.clickedRowId : rowIndex;
881
-
882
- this.rowsToSelect = new Array();
883
- for (var i = start; i <= end; i++) {
884
- this.rowsToSelect.push(i);
885
- }
886
-
887
- // this actually selects the rows
888
- this.selectRows();
889
- }
890
- };
891
-
892
- /**
893
- * Binds the needed selection-mouse events to the given cell
894
- *
895
- * @param cell
896
- * The jquery object of the table-data field
897
- * @return void
898
- */
899
- GENTICS.Aloha.Table.prototype.attachSelectionRow = function() {
900
- var that = this;
901
-
902
- // create an empty td
903
- var emptyCell = jQuery('<td>');
904
- emptyCell.html('\u00a0');
905
-
906
- // get the number of columns in the table (length of the cells in the first row)
907
- var numColumns = this.obj.context.rows[0].cells.length;
908
- var selectionRow = jQuery('<tr>');
909
- selectionRow.addClass(this.get('classSelectionRow'));
910
- selectionRow.css('height', this.get('selectionArea') + 'px');
911
- for (var i = 0; i < numColumns; i++) {
912
- var columnToInsert = emptyCell.clone();
913
-
914
- // the first cell should have no function, so only attach the events for
915
- // the rest
916
- if (i > 0) {
917
- // bind all mouse-events to the cell
918
- this.attachColumnSelectEventsToCell(columnToInsert);
919
- }
920
- // add the cell to the row
921
- selectionRow.append(columnToInsert);
922
- }
923
- // global mouseup event to reset the selection properties
924
- jQuery(document).bind('mouseup', function(e) {
925
- that.mousedown = false;
926
- that.clickedColumnId = -1;
927
- that.clickedRowId = -1;
928
- });
929
-
930
- selectionRow.find('td:first').addClass(this.get('classLeftUpperCorner'));
931
- this.obj.find('tr:first').before(selectionRow);
932
- };
933
-
934
- /**
935
- * Binds the events for the column selection to the given cell.
936
- *
937
- * @param cell
938
- * the jquery object of the td-field
939
- * @return void
940
- */
941
- GENTICS.Aloha.Table.prototype.attachColumnSelectEventsToCell = function (cell) {
942
- var that = this;
943
-
944
- // unbind eventually existing events of this cell
945
- cell.unbind('mousedown');
946
- cell.unbind('mouseover');
947
-
948
- // prevent ie from selecting the contents of the table
949
- cell.get(0).onselectstart = function() { return false; };
950
-
951
- cell.bind('mousedown', function(e) {
952
- that.columnSelectionMouseDown(e);
953
-
954
- // focus the table
955
- that.focus();
956
-
957
- // stop bubble, otherwise the mousedown of the table is called ...
958
- e.stopPropagation();
959
-
960
- return false;
961
- });
962
-
963
- cell.bind('mouseover', function (e) {
964
- that.columnSelectionMouseOver(e);
965
- });
966
- };
967
-
968
- /**
969
- * Mouse-down event for a columns-selection cell. It adds the index of the
970
- * clicked column to the "columnsToSelect"-Array and calls the method which
971
- * selects the column.
972
- *
973
- * @param jqEvent
974
- * the jquery event-object
975
- * @return void
976
- */
977
- GENTICS.Aloha.Table.prototype.columnSelectionMouseDown = function (jqEvent) {
978
- // set the mousedown flag
979
- this.mousedown = true;
980
-
981
- // if no cells are selected, reset the selection-array
982
- if (GENTICS.Aloha.TableHelper.selectedCells.length == 0) {
983
- this.columnsToSelect = new Array();
984
- }
985
-
986
- // store the id of the column which has been originally clicked
987
- this.clickedColumnId = jqEvent.currentTarget.cellIndex;
988
- if (jqEvent.ctrlKey) {
989
- var arrayIndex = jQuery.inArray(this.clickedColumnId, this.columnsToSelect);
990
- if (arrayIndex >= 0) {
991
- this.columnsToSelect.splice(arrayIndex, 1);
992
- }else{
993
- this.columnsToSelect.push(this.clickedColumnId);
994
- }
995
- }else if (jqEvent.shiftKey) {
996
- this.columnsToSelect.sort(function(a,b){return a - b;});
997
- var start = this.columnsToSelect[0];
998
- var end = this.clickedColumnId;
999
- if (start > end) {
1000
- start = end;
1001
- end = this.columnsToSelect[0];
1002
- }
1003
- this.columnsToSelect = new Array();
1004
- for (var i = start; i <= end; i++) {
1005
- this.columnsToSelect.push(i);
1006
- }
1007
- }else{
1008
- this.columnsToSelect = [this.clickedColumnId];
1009
- }
1010
-
1011
- // this does actually the column-selection.
1012
- // it reads the columns which should be selected from "columnsToSelect"
1013
- this.selectColumns();
1014
-
1015
- // prevent browser from selecting the table
1016
- jqEvent.preventDefault();
1017
- };
1018
-
1019
- /**
1020
- * Mouseover-event for the column-selection cell. This method calcluates the
1021
- * span between the clicked column and the mouse-overed cell and selects the
1022
- * columns inbetween. and mark them as selected
1023
- *
1024
- * @param jqEvent
1025
- * the jquery-event object
1026
- * @return void
1027
- */
1028
- GENTICS.Aloha.Table.prototype.columnSelectionMouseOver = function (jqEvent) {
1029
- var colIndex = jqEvent.currentTarget.cellIndex;
1030
- if (this.mousedown && this.clickedColumnId > 0) {
1031
- var indexInArray = jQuery.inArray(colIndex, this.columnsToSelect);
1032
-
1033
- var start = (colIndex < this.clickedColumnId) ? colIndex : this.clickedColumnId;
1034
- var end = (colIndex < this.clickedColumnId) ? this.clickedColumnId : colIndex;
1035
-
1036
- this.columnsToSelect = new Array();
1037
- for (var i = start; i <= end; i++) {
1038
- this.columnsToSelect.push(i);
1039
- }
1040
-
1041
- this.selectColumns();
1042
- }
1043
- };
1044
-
1045
- /**
1046
- * Unbinds all events of the last cell
1047
- *
1048
- * @return void
1049
- */
1050
- GENTICS.Aloha.Table.prototype.releaseLastCellEvents = function() {
1051
- this.obj.find('tr:last td:last').unbind();
1052
- };
1053
-
1054
- /**
1055
- * Attach a keydown-event for the last cell
1056
- *
1057
- * @see GENTICS.Aloha.Table.lastCellKeyDown
1058
- * @return void
1059
- */
1060
- GENTICS.Aloha.Table.prototype.attachLastCellEvents = function() {
1061
- var that = this;
1062
- this.obj.find('tr:last td:last').bind('keydown', function(jqEvent) {
1063
- that.lastCellKeyDown(jqEvent);
1064
- });
1065
- };
1066
-
1067
- /**
1068
- * If the tab-key was pressed in the last cell create a new row and jump into
1069
- * the first cell of the next row.
1070
- * Only add a new row if no addtional key was pressed (shift, alt, ctrl)
1071
- *
1072
- * @param jqEvent
1073
- * the jquery-event object
1074
- * @return
1075
- */
1076
- GENTICS.Aloha.Table.prototype.lastCellKeyDown = function(jqEvent) {
1077
- var KEYCODE_TAB = 9;
1078
-
1079
- // only add a row on a single key-press of tab (so check if alt-, shift- or
1080
- // ctrl-key are NOT pressed)
1081
- if (KEYCODE_TAB == jqEvent.keyCode && !jqEvent.altKey && !jqEvent.shiftKey && !jqEvent.ctrlKey) {
1082
- // add a row after the current row (false stands for not highlighting the new row)
1083
- this.addRowsAfter(false);
1084
-
1085
- // stop propagation because this should overwrite all other events
1086
- jqEvent.stopPropagation();
1087
-
1088
- // for ie make a special case ... focus the first cell of the new row
1089
- if (jQuery.browser.msie) {
1090
- this.obj.find('tr:last td:nth-child(1) div.GENTICS_Table_Cell_editable').get(0).focus();
1091
- return false;
1092
- }
1093
- }
1094
- };
1095
-
1096
- /**
1097
- * Deletes the selected rows. If no row are selected, delete the row, where the
1098
- * cursor is positioned. If all rows of the table should be deleted, the whole
1099
- * table is deletet and removed from the tableRegistry.
1100
- *
1101
- * @return void
1102
- */
1103
- GENTICS.Aloha.Table.prototype.deleteRows = function() {
1104
- var rowIDs = new Array();
1105
-
1106
- // flag if the table should be deleted
1107
- var deleteTable = false;
1108
-
1109
- // if a selection was made, delete the selected cells
1110
- if (GENTICS.Aloha.TableHelper.selectedCells.length > 0) {
1111
- for (var i = 0; i < GENTICS.Aloha.TableHelper.selectedCells.length; i++) {
1112
- rowIDs.push(GENTICS.Aloha.TableHelper.selectedCells[i][0].parentNode.rowIndex);
1113
- }
1114
-
1115
- // if no rows were selected, delete the row, where the cursor is placed in
1116
- }else if (typeof GENTICS.Aloha.Table.Cell.lastActiveCell != 'undefined') {
1117
- rowIDs.push(GENTICS.Aloha.Table.Cell.lastActiveCell.obj.context.parentNode.rowIndex);
1118
- }
1119
-
1120
- // if all rows should be deleted, set flag to remove the WHOLE table
1121
- if (rowIDs.length == this.numRows) {
1122
- deleteTable = true;
1123
- }
1124
-
1125
- // delete the whole table
1126
- if (deleteTable) {
1127
- if (window.confirm('You have selected all rows to be deleted. This will delete the table.\nContinue?')) {
1128
- this.deleteTable();
1129
- }
1130
-
1131
- }else{
1132
- rowIDs.sort(function(a,b){return a - b;});
1133
- // check which cell should be focused after the deletion
1134
- var focusRowId = rowIDs[0];
1135
- if (focusRowId > (this.numRows - rowIDs.length)) {
1136
- focusRowId --;
1137
- }
1138
-
1139
- // release the events of the last cell
1140
- this.releaseLastCellEvents();
1141
-
1142
- // get all rows
1143
- var rows = this.obj.find('tr');
1144
- var rows2delete = new Array();
1145
-
1146
- // build the array with the row-ids of th rows which should be deleted
1147
- for (var i = 0; i < rowIDs.length; i++) {
1148
- rows2delete.push(jQuery(rows[rowIDs[i]]));
1149
- }
1150
-
1151
- // delete cells from cells-array
1152
- for (var i = 0; i < rows2delete.length; i ++) {
1153
- var cols = rows2delete[i].children("td").toArray();
1154
- for (var j = 0; j < cols.length; j++) {
1155
- for (var m = 0; m < this.cells.length; m ++) {
1156
- if (cols[j] == this.cells[m].obj.get(0)) {
1157
- this.cells.splice(m, 1);
1158
- m = this.cells.length;
1159
- }
1160
- }
1161
- }
1162
- }
1163
-
1164
- // remove the rows
1165
- for (var i = 0; i < rows2delete.length; i++) {
1166
- rows2delete[i].remove();
1167
- }
1168
-
1169
- // reduce the attribute storing the number of rows in the table
1170
- this.numRows -= rows2delete.length;
1171
-
1172
- if (jQuery.browser.msie){
1173
- setTimeout(this.obj.find('tr:nth-child(' + (focusRowId + 1) + ') td:nth-child(2) div.GENTICS_Table_Cell_editable').get(0).focus, 5);
1174
- }else{
1175
- this.obj.find('tr:nth-child(' + (focusRowId + 1) + ') td:nth-child(2) div.GENTICS_Table_Cell_editable').get(0).focus();
1176
- }
1177
-
1178
- // re-attach the events for the last cell
1179
- this.attachLastCellEvents();
1180
-
1181
- // finally unselect the marked cells
1182
- GENTICS.Aloha.TableHelper.unselectCells();
1183
- }
1184
- };
1185
-
1186
- /**
1187
- * Deletes the selected columns. If no columns are selected, delete the column, where the
1188
- * cursor is positioned. If all columns of the table should be deleted, the whole
1189
- * table is deleted from the dom and removed from the tableRegistry.
1190
- *
1191
- * @return void
1192
- */
1193
- GENTICS.Aloha.Table.prototype.deleteColumns = function() {
1194
- var colIDs = new Array();
1195
-
1196
- // flag if the table should be deleted
1197
- var deleteTable = false;
1198
-
1199
- // if a selection was made, delete the selected cells
1200
- if (GENTICS.Aloha.TableHelper.selectedCells.length > 0) {
1201
- for (var i = 0; i < GENTICS.Aloha.TableHelper.selectedCells[0].length; i++) {
1202
- colIDs.push(GENTICS.Aloha.TableHelper.selectedCells[0][i].cellIndex);
1203
- }
1204
-
1205
- // if no columns were selected, delete the column, where the cursor is placed in
1206
- }else if (typeof GENTICS.Aloha.Table.Cell.lastActiveCell != 'undefined') {
1207
- colIDs.push(GENTICS.Aloha.Table.Cell.lastActiveCell.obj.context.cellIndex);
1208
- }
1209
-
1210
- // if all columns should be deleted, set flag to remove the WHOLE table
1211
- if (colIDs.length == this.numCols) {
1212
- deleteTable = true;
1213
- }
1214
-
1215
- // delete the whole table
1216
- if (deleteTable) {
1217
- if (window.confirm('You have selected all columns to be deleted. This will delete the table.\nContinue?')) {
1218
- this.deleteTable();
1219
- }
1220
-
1221
- }else{
1222
- colIDs.sort(function(a,b){return a - b;});
1223
- // check which cell should be focused after the deletion
1224
- var focusColID = colIDs[0];
1225
- if (focusColID > (this.numCols - colIDs.length)) {
1226
- focusColID --;
1227
- }
1228
-
1229
- // release the events of the last cell
1230
- this.releaseLastCellEvents();
1231
-
1232
- // get all rows to iterate
1233
- var rows = this.obj.find('tr');
1234
- var cols2delete = new Array();
1235
-
1236
- // build the array with the row-ids of th rows which should be deleted
1237
- for (var i = 0; i < rows.length; i++) {
1238
- var cells = jQuery(rows[i]).children("td").toArray();
1239
- for (var j = 0; j < colIDs.length; j++) {
1240
- cols2delete.push(cells[colIDs[j]]);
1241
- }
1242
- }
1243
-
1244
- // delete cells from cells-array
1245
- for (var i = 0; i < cols2delete.length; i ++) {
1246
- for (var j = 0; j < this.cells.length; j++) {
1247
- if (cols2delete[i] == this.cells[j].obj.get(0)) {
1248
- this.cells.splice(j, 1);
1249
- j = this.cells.length;
1250
- }
1251
- }
1252
- }
1253
-
1254
- // remove the columns
1255
- for (var i = 0; i < cols2delete.length; i++) {
1256
- jQuery(cols2delete[i]).remove();
1257
- }
1258
-
1259
- // reduce the attribute storing the number of rows in the table
1260
- this.numCols -= colIDs.length;
1261
-
1262
- if (jQuery.browser.msie){
1263
- setTimeout(this.obj.find('tr:nth-child(2) td:nth-child(' + (focusColID + 1) + ') div.GENTICS_Table_Cell_editable').get(0).focus, 5);
1264
- }else{
1265
- this.obj.find('tr:nth-child(2) td:nth-child(' + (focusColID + 1) + ') div.GENTICS_Table_Cell_editable').get(0).focus();
1266
- }
1267
-
1268
- // re-attach the events for the last cell
1269
- this.attachLastCellEvents();
1270
-
1271
- GENTICS.Aloha.TableHelper.unselectCells();
1272
- }
1273
- };
1274
-
1275
- /**
1276
- * Deletes the table from the dom and remove it from the tableRegistry.
1277
- *
1278
- * @return void
1279
- */
1280
- GENTICS.Aloha.Table.prototype.deleteTable = function() {
1281
- var deleteIndex = -1;
1282
- for (var i = 0; i < GENTICS.Aloha.SimpleTablePlugin.TableRegistry.length; i++){
1283
- if (GENTICS.Aloha.SimpleTablePlugin.TableRegistry[i].obj.attr('id') == this.obj.attr('id')) {
1284
- deleteIndex = i;
1285
- break;
1286
- }
1287
- }
1288
- if (deleteIndex >= 0) {
1289
- GENTICS.Aloha.SimpleTablePlugin.TableRegistry.splice(i, 1);
1290
- this.obj.remove();
1291
- this.parentEditable.obj.focus();
1292
- this.parentEditable.floatingMenu.call();
1293
- delete this;
1294
- }
1295
- };
1296
-
1297
- /**
1298
- * Wrapper function for this.addRow to add a row before the active row
1299
- *
1300
- * @param highlightNewRows flag if the newly created rows should be marked as selected
1301
- * @see GENTICS.Aloha.Table.prototype.addRow
1302
- * @return
1303
- */
1304
- GENTICS.Aloha.Table.prototype.addRowsBefore = function(highlightNewRows) {
1305
- this.addRows('before', highlightNewRows);
1306
- };
1307
-
1308
- /**
1309
- * Wrapper function for this.addRow to add a row after the active row
1310
- *
1311
- * @param highlightNewRows flag if the newly created rows should be marked as selected
1312
- * @see GENTICS.Aloha.Table.prototype.addRow
1313
- * @return
1314
- */
1315
- GENTICS.Aloha.Table.prototype.addRowsAfter = function(highlightNewRows) {
1316
- this.addRows('after', highlightNewRows);
1317
- };
1318
-
1319
- /**
1320
- * Adds new rows to the table. If rows were selected, the new rows will be
1321
- * inserted before/after the first/last selected row. If no rows are selected, a
1322
- * new row will be inserted before/after the row of the currently selected cell.
1323
- * As well the row-selection events have to be bound again.
1324
- *
1325
- * @param position
1326
- * could be 'after' or 'before'. defines the position where the new
1327
- * rows should be inserted
1328
- * @param highlightNewRows
1329
- * flag if the newly created rows should be marked as selected
1330
- * @return void
1331
- */
1332
- GENTICS.Aloha.Table.prototype.addRows = function(position, highlightNewRows) {
1333
- if (typeof GENTICS.Aloha.SimpleTablePlugin.activeTable != 'undefined') {
1334
- // release listening events of the last cell
1335
- this.releaseLastCellEvents();
1336
-
1337
- var that = this;
1338
- var numCols = this.numCols;
1339
-
1340
- // number of rows to insert
1341
- var rowsToInsert = 1;
1342
- // index where new rows should be inserted
1343
- var rowId = 1;
1344
-
1345
- // if rows were selected take the amount of selected cells for the new rows
1346
- if (GENTICS.Aloha.TableHelper.selectedCells.length > 0) {
1347
- rowsToInsert = GENTICS.Aloha.TableHelper.selectedCells.length;
1348
-
1349
- // get the index where the new rows should be inserted
1350
- switch (position) {
1351
- case 'before':
1352
- if (GENTICS.Aloha.TableHelper.selectedCells[0].length){
1353
- rowId = GENTICS.Aloha.TableHelper.selectedCells[0][0].parentNode.rowIndex;
1354
- }
1355
- break;
1356
- case 'after':
1357
- var lastRow = GENTICS.Aloha.TableHelper.selectedCells.length - 1;
1358
- if (GENTICS.Aloha.TableHelper.selectedCells[lastRow].length){
1359
- rowId = GENTICS.Aloha.TableHelper.selectedCells[lastRow][0].parentNode.rowIndex;
1360
- }
1361
- break;
1362
- }
1363
-
1364
- // no rows selected, insert 1 new row before/after the row of the last active cell
1365
- }else if (typeof GENTICS.Aloha.Table.Cell.lastActiveCell != 'undefined') {
1366
- rowId = GENTICS.Aloha.Table.Cell.lastActiveCell.obj.context.parentNode.rowIndex;
1367
- }
1368
-
1369
- // the new row index for the created row
1370
- var newRowIndex = rowId;
1371
- // if the new rows should be inserted after the last selected row
1372
- // increase the rowindex will be one more than the actual row
1373
- if (position == 'after') {
1374
- newRowIndex += 1;
1375
- }
1376
-
1377
- var rowIdArray = new Array();
1378
- for (var j = 0; j < rowsToInsert; j++) {
1379
- rowIdArray.push(newRowIndex);
1380
- var insertionRow = jQuery('<tr>');
1381
-
1382
- // create the first column, the "select row" column
1383
- var selectionColumn = jQuery('<td>');
1384
- selectionColumn.addClass(this.get('classSelectionColumn'));
1385
- this.attachRowSelectionEventsToCell(selectionColumn);
1386
- insertionRow.append(selectionColumn);
1387
-
1388
- for (i = 0; i < numCols; i++) {
1389
- var newCol = jQuery('<td>');
1390
- newCol.html('\u00a0');
1391
- var cell = new GENTICS.Aloha.Table.Cell(newCol.get(0), GENTICS.Aloha.SimpleTablePlugin.activeTable);
1392
- cell.activate();
1393
- this.cells.push(cell);
1394
-
1395
- insertionRow.append(cell.obj);
1396
- }
1397
-
1398
-
1399
- var currentRow = jQuery(GENTICS.Aloha.SimpleTablePlugin.activeTable.obj.find("tr").get(rowId));
1400
-
1401
- switch (position) {
1402
- case 'before':
1403
- currentRow.before(insertionRow);
1404
- break;
1405
- case 'after':
1406
- currentRow.after(insertionRow);
1407
- break;
1408
- default:
1409
- this.warn(this, 'Wrong call of GENTICS.Aloha.Table.prototype.addRow!');
1410
- }
1411
- newRowIndex ++;
1412
- this.numRows ++;
1413
- }
1414
- GENTICS.Aloha.TableHelper.unselectCells();
1415
-
1416
- this.rowsToSelect = rowIdArray;
1417
- if (highlightNewRows) {
1418
- this.selectRows();
1419
- }
1420
-
1421
- // re-attach events of the last cell
1422
- this.attachLastCellEvents();
1423
- }
1424
- };
1425
-
1426
- /**
1427
- * Wrapper method to add columns on the right side
1428
- *
1429
- * @see GENTICS.Aloha.Table.addColumns
1430
- * @return void
1431
- */
1432
- GENTICS.Aloha.Table.prototype.addColumnsRight = function () {
1433
- this.addColumns('right');
1434
- };
1435
-
1436
- /**
1437
- * Wrapper method to add columns on the left side
1438
- *
1439
- * @see GENTICS.Aloha.Table.addColumns
1440
- * @return void
1441
- */
1442
- GENTICS.Aloha.Table.prototype.addColumnsLeft = function() {
1443
- this.addColumns('left');
1444
- };
1445
-
1446
- /**
1447
- * Inserts new columns into the table. Either on the right or left side. If
1448
- * columns are selected, the amount of selected columns will be inserted on the
1449
- * 'right' or 'left' side. If no cells are selected, 1 new column will be
1450
- * inserted before/after the column of the last active cell.
1451
- * As well all column-selection events must be bound to the firsts row-cell.
1452
- *
1453
- * @param position
1454
- * could be 'left' or 'right'. defines the position where the new
1455
- * columns should be inserted
1456
- * @return void
1457
- */
1458
- GENTICS.Aloha.Table.prototype.addColumns = function (position) {
1459
- if (typeof GENTICS.Aloha.SimpleTablePlugin.activeTable != 'undefined') {
1460
- // release listening events of the last cell
1461
- this.releaseLastCellEvents();
1462
-
1463
- var that = this;
1464
-
1465
- // amount of columns to insert
1466
- var columnsToInsert = 1;
1467
- // index of the column from where the new columns should be inserted
1468
- var colId = 1;
1469
-
1470
- // if columns are selected, get the column-index of the column on the left/right selected end
1471
- if (GENTICS.Aloha.TableHelper.selectedCells.length > 0) {
1472
- columnsToInsert = GENTICS.Aloha.TableHelper.selectedCells[0].length;
1473
- switch (position) {
1474
- case 'left':
1475
- if (GENTICS.Aloha.TableHelper.selectedCells[0].length){
1476
- colId = GENTICS.Aloha.TableHelper.selectedCells[0][0].cellIndex;
1477
- }
1478
- break;
1479
- case 'right':
1480
- var lastColumn = GENTICS.Aloha.TableHelper.selectedCells[0].length - 1;
1481
- if (GENTICS.Aloha.TableHelper.selectedCells[0].length){
1482
- colId = GENTICS.Aloha.TableHelper.selectedCells[0][lastColumn].cellIndex;
1483
- }
1484
- break;
1485
- }
1486
- // otherwise take the column-index of the last active cell
1487
- }else if (typeof GENTICS.Aloha.Table.Cell.lastActiveCell != 'undefined') {
1488
- colId = GENTICS.Aloha.Table.Cell.lastActiveCell.obj.context.cellIndex;
1489
- }
1490
-
1491
- // the new col index for the created column
1492
- var newColId = colId;
1493
-
1494
- var emptyCell = jQuery('<td>');
1495
- var rows = this.obj.find('tr');
1496
- var colIdArray = new Array();
1497
- for (var i = 0; i < rows.length; i++){
1498
- var currentColId = newColId;
1499
- var row = rows[i];
1500
-
1501
- for (var j = 0; j < columnsToInsert; j++) {
1502
- var cell = emptyCell.clone();
1503
- cell.html('\u00a0');
1504
- // this is the first row, so make a column-selection cell
1505
- if (i == 0) {
1506
- this.attachColumnSelectEventsToCell(cell);
1507
-
1508
- }else{
1509
- cellObj = new GENTICS.Aloha.Table.Cell(cell.get(0), GENTICS.Aloha.SimpleTablePlugin.activeTable);
1510
- this.cells.push(cellObj);
1511
- cellObj.activate();
1512
- cell = cellObj.obj;
1513
- }
1514
-
1515
- var insertionColumn = jQuery(jQuery(row).find("td").get(newColId));
1516
- switch (position) {
1517
- case 'left':
1518
- if (jQuery.inArray(currentColId, colIdArray) < 0) {
1519
- colIdArray.push(currentColId);
1520
- }
1521
- insertionColumn.before(cell);
1522
- break;
1523
- case 'right':
1524
- if (jQuery.inArray((currentColId + 1), colIdArray) < 0) {
1525
- colIdArray.push(currentColId + 1);
1526
- }
1527
- insertionColumn.after(cell);
1528
- break;
1529
- }
1530
- currentColId ++;
1531
- }
1532
- }
1533
- this.numCols += columnsToInsert;
1534
- GENTICS.Aloha.TableHelper.unselectCells();
1535
- this.columnsToSelect = colIdArray;
1536
- this.selectColumns();
1537
-
1538
- // re-attach events of the last cell
1539
- this.attachLastCellEvents();
1540
- }
1541
- };
1542
-
1543
- /**
1544
- * Helper method to set the focus-attribute of the table to true
1545
- *
1546
- * @return void
1547
- */
1548
- GENTICS.Aloha.Table.prototype.focus = function() {
1549
- if (!this.hasFocus) {
1550
- if (!this.parentEditable.isActive) {
1551
- this.parentEditable.obj.focus();
1552
- }
1553
-
1554
- GENTICS.Aloha.SimpleTablePlugin.setFocusedTable(this);
1555
- this.floatingMenu.call();
1556
- }
1557
-
1558
- // TODO workaround - fix this. the selection is updated later on by the browser
1559
- // using setTimeout here is hideous, but a simple execution-time call will fail
1560
- setTimeout('GENTICS.Aloha.Selection.updateSelection(false, true)', 50);
1561
-
1562
- };
1563
-
1564
- /**
1565
- * Helper method to set the focus-attribute of the table to false
1566
- *
1567
- * @return void
1568
- */
1569
- GENTICS.Aloha.Table.prototype.focusOut = function() {
1570
- if (this.hasFocus) {
1571
- this.hasFocus = false;
1572
- GENTICS.Aloha.SimpleTablePlugin.setFocusedTable(undefined);
1573
- }
1574
- };
1575
-
1576
- /**
1577
- * Marks all cells of the specified column as marked (adds a special class)
1578
- *
1579
- * @return void
1580
- */
1581
- GENTICS.Aloha.Table.prototype.selectColumns = function() {
1582
- // get the class which selected cells should have
1583
- var selectClass = this.get('classCellSelected');
1584
-
1585
- // unselect selected cells
1586
- GENTICS.Aloha.TableHelper.unselectCells();
1587
-
1588
- GENTICS.Aloha.TableHelper.selectionType = 'col';
1589
-
1590
- this.columnsToSelect.sort(function(a,b){return a - b;});
1591
-
1592
- var rows = this.obj.find("tr").toArray();
1593
- // first row is the selection row (dump it => not needed)
1594
- rows.shift();
1595
- var toSelect = new Array();
1596
- for (var i = 0; i < rows.length; i++){
1597
- var rowCells = rows[i].cells;
1598
-
1599
- var selectedCellsInCol = new Array();
1600
- for (var j = 0; j < this.columnsToSelect.length; j++) {
1601
- var colIndex = this.columnsToSelect[j];
1602
- var cell = rowCells[colIndex];
1603
- toSelect.push(cell);
1604
- if (i == 0 && j == 0) {
1605
- if (jQuery.browser.msie) {
1606
- // setTimeout(jQuery(cell).children('div.GENTICS_Table_Cell_editable').get(0).focus, 5);
1607
- }else{
1608
- jQuery(cell).children('div.GENTICS_Table_Cell_editable').get(0).focus();
1609
- }
1610
- }
1611
- selectedCellsInCol.push(cell);
1612
- }
1613
- GENTICS.Aloha.TableHelper.selectedCells.push(selectedCellsInCol);
1614
- };
1615
- jQuery(toSelect).addClass(selectClass);
1616
- };
1617
-
1618
-
1619
- /**
1620
- * Marks all cells of the specified row as marked (adds a special class)
1621
- *
1622
- * @return void
1623
- */
1624
- GENTICS.Aloha.Table.prototype.selectRows = function() {
1625
- // get the class which selected cells should have
1626
- var selectClass = this.get('classCellSelected');
1627
-
1628
- // unselect selected cells
1629
- GENTICS.Aloha.TableHelper.unselectCells();
1630
- this.rowsToSelect.sort(function(a,b){return a - b;});
1631
-
1632
- for (var i = 0; i < this.rowsToSelect.length; i++) {
1633
- var rowId = this.rowsToSelect[i];
1634
- var rowCells = jQuery(this.obj.find('tr').get(rowId).cells).toArray();
1635
-
1636
- // shift the first element (which is a selection-helper cell)
1637
- rowCells.shift();
1638
-
1639
- GENTICS.Aloha.TableHelper.selectedCells.push(rowCells);
1640
- if (i == 0) {
1641
- if (jQuery.browser.msie) {
1642
- // setTimeout(jQuery(rowCells[0]).children('div.GENTICS_Table_Cell_editable').get(0).focus, 5);
1643
- }else{
1644
- jQuery(rowCells[0]).children('div.GENTICS_Table_Cell_editable').get(0).focus();
1645
- }
1646
- }
1647
- jQuery(rowCells).addClass(this.get('classCellSelected'));
1648
- }
1649
- GENTICS.Aloha.TableHelper.selectionType = 'row';
1650
- };
1651
-
1652
-
1653
- /**
1654
- * Deactivation of a Aloha-Table. Clean up ... remove the wrapping div and the
1655
- * selection-helper divs
1656
- *
1657
- * @return void
1658
- */
1659
- GENTICS.Aloha.Table.prototype.deactivate = function() {
1660
- this.obj.removeClass(this.get('className'));
1661
- if (GENTICS.Aloha.trim(this.obj.attr('class')) == '') {
1662
- this.obj.removeAttr('class');
1663
- }
1664
- this.obj.removeAttr('contenteditable');
1665
- this.obj.removeAttr('id');
1666
-
1667
- // unwrap the selectionLeft-div if available
1668
- if (this.obj.parents('.' + this.get('classTableWrapper')).length){
1669
- this.obj.unwrap();
1670
- }
1671
-
1672
- // remove the selection row
1673
- this.obj.find('tr.' + this.get('classSelectionRow') + ':first').remove();
1674
- // remove the selection column (first column left)
1675
- var that = this;
1676
- jQuery.each(this.obj.context.rows, function(){
1677
- jQuery(this).children('td.' + that.get('classSelectionColumn')).remove();
1678
- });
1679
-
1680
- // remove the "selection class" from all td and th in the table
1681
- this.obj.find('td, th').removeClass(this.get('classCellSelected'));
1682
- this.obj.unbind();
1683
- // wrap the inner html of the contentEditable div to its outer html
1684
- for (var i = 0; i < this.cells.length; i++) {
1685
- var Cell = this.cells[i];
1686
- Cell.deactivate();
1687
- }
1688
- };
1689
-
1690
- /**
1691
- * toString-method for GENTICS.Aloha.Table object
1692
- *
1693
- * @return void
1694
- */
1695
- GENTICS.Aloha.Table.prototype.toString = function() {
1696
- return 'GENTICS.Aloha.Table';
1697
- };
1698
- /* -- END METHODS -- */
1699
-
1700
-
1701
- /*****************************
1702
- +--------------------------+
1703
- | GENTICS.Aloha.Table.Cell |
1704
- +--------------------------+
1705
- ******************************/
1706
-
1707
- /**
1708
- * The constructor for the Cell-Objects takes a DOM td-object, attaches
1709
- * events, adds an wrapper into the cell and returns the modified td-object as
1710
- * DOM representation
1711
- *
1712
- * @param originalTd
1713
- * The original td-field which should will be transformed
1714
- * @param colId
1715
- * the internal id of the corresponding col (begin with 0)
1716
- * @param rowId
1717
- * the internal id of the corresponding row (begin with 0)
1718
- * @param tableObj
1719
- * GENTICS.Aloha.Table-Object which contains the cell
1720
- *
1721
- * @return the created table-data field as DOM-representation
1722
- */
1723
- GENTICS.Aloha.Table.Cell = function(originalTd, tableObj) {
1724
- this.obj = jQuery(originalTd);
1725
- this.tableObj = tableObj;
1726
- };
1727
- /* -- ATTRIBUTES -- */
1728
- /**
1729
- * Reference to the jQuery-representation of the wrapping table
1730
- *
1731
- * @see GENTICS.Aloha.Table.Cell.table
1732
- */
1733
- GENTICS.Aloha.Table.Cell.prototype.tableObj = undefined;
1734
-
1735
- /**
1736
- * Reference to the jQuery td-Object of the cell
1737
- */
1738
- GENTICS.Aloha.Table.Cell.prototype.obj = undefined;
1739
-
1740
- /**
1741
- * The jQuery wrapper of the cell
1742
- */
1743
- GENTICS.Aloha.Table.Cell.prototype.wrapper = undefined;
1744
-
1745
- /**
1746
- * Flag if the cell has focus
1747
- */
1748
- GENTICS.Aloha.Table.Cell.prototype.hasFocus = false;
1749
-
1750
- /**
1751
- * The jQuery wrapper of the cell
1752
- */
1753
- GENTICS.Aloha.Table.Cell.activeCell = undefined;
1754
-
1755
- /**
1756
- * The jQuery wrapper of the cell
1757
- */
1758
- GENTICS.Aloha.Table.Cell.lastActiveCell = undefined;
1759
- /* -- END ATTRIBUTES -- */
1760
-
1761
-
1762
- /**
1763
- * Focus method for the contentediable div within a table data-field. The method
1764
- * requires the event-property Cell as a GENTICS.Aloha.Table.Cell object. If the
1765
- * Cell wasn't activated yet it does all relevant actions to activate the cell.
1766
- *
1767
- * @param e
1768
- * the jquery event object
1769
- * @return void
1770
- */
1771
- GENTICS.Aloha.Table.Cell.prototype.editableFocus = function(e) {
1772
- // only do activation stuff if the cell don't has the focus
1773
- if (!this.hasFocus) {
1774
- // set an internal flag to focus the table
1775
- this.tableObj.focus();
1776
-
1777
- // set the clicked cell active as the active cell
1778
- GENTICS.Aloha.Table.Cell.activeCell = this;
1779
-
1780
- // set the clicked cell active as the last active cell (the difference
1781
- // to activeCell is that lastActiveCell won't be reset on blur)
1782
- GENTICS.Aloha.Table.Cell.lastActiveCell = this;
1783
-
1784
- // add an active-class
1785
- this.obj.addClass('GENTICS_Table_Cell_active');
1786
-
1787
- // set the focus flag
1788
- this.hasFocus = true;
1789
-
1790
- // select the whole content in the table-data field
1791
- this.selectAll(this.wrapper.get(0));
1792
- }
1793
- };
1794
-
1795
- /**
1796
- * Blur event for the contenteditable div within a table-data field. The method
1797
- * requires the event-property Cell as a GENTICS.Aloha.Table.Cell object. It
1798
- * sets the hasFocus flag of the cell to false and removes the "active"
1799
- * css-class.
1800
- *
1801
- * @param jqEvent
1802
- * the jquery event object
1803
- * @return void
1804
- */
1805
- GENTICS.Aloha.Table.Cell.prototype.editableBlur = function(jqEvent){
1806
- // no active cell
1807
- GENTICS.Aloha.Table.Cell.activeCell = undefined;
1808
-
1809
- // reset the focus of the cell
1810
- this.hasFocus = false;
1811
-
1812
- // remove "active class"
1813
- this.obj.removeClass('GENTICS_Table_Cell_active');
1814
- };
1815
-
1816
- GENTICS.Aloha.Table.Cell.prototype.activate = function() {
1817
- // create the editable wrapper for the cells
1818
- // var wrapper = jQuery('<div>');
1819
- // wrapper.attr('contentEditable', 'true');
1820
- // wrapper.addClass('GENTICS_Table_Cell_editable');
1821
- //
1822
- // var that = this;
1823
- // // attach events to the editable div-object
1824
- // wrapper.bind('focus', function(jqEvent) { that.editableFocus(jqEvent); });
1825
- // wrapper.bind('mousedown', function(jqEvent) { that.editableMouseDown(jqEvent); });
1826
- // wrapper.bind('blur', function(jqEvent) { that.editableBlur(jqEvent); });
1827
- // wrapper.bind('keyup', function(jqEvent) { that.editableKeyUp(jqEvent); });
1828
- // wrapper.bind('keydown', function(jqEvent) { that.editableKeyDown(jqEvent); });
1829
- //
1830
- // this.obj.bind('mousedown', function(jqEvent) {
1831
- // setTimeout(function() {
1832
- // that.wrapper.trigger('focus');
1833
- // }, 1);
1834
- //
1835
- // // unselect cells
1836
- // GENTICS.Aloha.TableHelper.unselectCells();
1837
- //
1838
- // jqEvent.stopPropagation();
1839
- // });
1840
- // this.obj.get(0).onselectstart = function (jqEvent) { return false; };
1841
- //
1842
- // // wrap the created div into the contents of the cell
1843
- // this.obj.wrapInner(wrapper);
1844
- //
1845
- // // set contenteditable wrapper div
1846
- // this.wrapper = this.obj.children();
1847
- // this.wrapper.get(0).onselectstart = function() {
1848
- // window.event.cancelBubble = true;
1849
- // };
1850
-
1851
- return this;
1852
- };
1853
-
1854
- /**
1855
- * The deactivate method removes the contenteditable helper div within the
1856
- * table-data field and wraps the innerHtml to the outerHTML
1857
- *
1858
- * @return void
1859
- */
1860
- GENTICS.Aloha.Table.Cell.prototype.deactivate = function() {
1861
- var wrapper = this.obj.children('.GENTICS_Table_Cell_editable');
1862
-
1863
- if (wrapper.length) {
1864
- // get the inner html of the contenteditable div
1865
- var innerHtml = wrapper.html();
1866
-
1867
- // remove the contenteditable div and its attached events
1868
- wrapper.unbind();
1869
- wrapper.remove();
1870
-
1871
- // remove the click event of the
1872
- this.obj.unbind('click');
1873
-
1874
- if (GENTICS.Aloha.trim(this.obj.attr('class')) == '') {
1875
- this.obj.removeAttr('class');
1876
- }
1877
-
1878
- // set the inner html of the contenteditable div as html for the table-data
1879
- // field
1880
- this.obj.html(innerHtml);
1881
- }
1882
- };
1883
-
1884
- /**
1885
- * Native toString-method
1886
- *
1887
- * @return string name of the namespace
1888
- */
1889
- GENTICS.Aloha.Table.Cell.prototype.toString = function() {
1890
- return 'GENTICS.Aloha.Table.Cell';
1891
- };
1892
-
1893
- /**
1894
- * Selects all inner-contens of an contentEditable-object
1895
- *
1896
- * @param editableNode dom-representation of the editable node (div-element)
1897
- * @return void
1898
- */
1899
- GENTICS.Aloha.Table.Cell.prototype.selectAll = function(editableNode) {
1900
- var e = (editableNode.jquery) ? editableNode.get(0) : editableNode;
1901
-
1902
- // Not IE
1903
- if (!jQuery.browser.msie) {
1904
- var s = window.getSelection();
1905
- // Safari
1906
- if (s.setBaseAndExtent) {
1907
- s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
1908
- }
1909
- // Firefox and Opera
1910
- else {
1911
- // workaround for bug # 42885
1912
- if (window.opera
1913
- && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>') {
1914
- e.innerHTML = e.innerHTML + '&nbsp;';
1915
- }
1916
-
1917
- var r = document.createRange();
1918
- r.selectNodeContents(e);
1919
- s.removeAllRanges();
1920
- s.addRange(r);
1921
- }
1922
- }
1923
- // Some older browsers
1924
- else if (document.getSelection) {
1925
- var s = document.getSelection();
1926
- var r = document.createRange();
1927
- r.selectNodeContents(e);
1928
- s.removeAllRanges();
1929
- s.addRange(r);
1930
- }
1931
- // IE
1932
- else if (document.selection) {
1933
- var r = document.body.createTextRange();
1934
- r.moveToElementText(e);
1935
- r.select();
1936
- }
1937
-
1938
- GENTICS.Aloha.Selection.updateSelection(editableNode);
1939
- };
1940
-
1941
- /**
1942
- * The mouse-down event for the editable-div in the thd-field. Unselect all
1943
- * cells when clicking on the editable-div.
1944
- *
1945
- * @param jqEvent
1946
- * the jquery-event object
1947
- * @return void
1948
- */
1949
- GENTICS.Aloha.Table.Cell.prototype.editableMouseDown = function(jqEvent) {
1950
- // deselect all highlighted cells registred in the TableHelper object
1951
- GENTICS.Aloha.TableHelper.unselectCells();
1952
-
1953
- if (this.tableObj.hasFocus) {
1954
- jqEvent.stopPropagation();
1955
- }
1956
- };
1957
-
1958
- /**
1959
- * The key-up event for the editable-div in the td-field. Just check if the div
1960
- * is empty and insert an &nbsp;
1961
- *
1962
- * @param jqEvent
1963
- * the jquery-event object
1964
- * @return void
1965
- */
1966
- GENTICS.Aloha.Table.Cell.prototype.editableKeyUp = function(jqEvent) {
1967
- this.checkForEmptyEvent(jqEvent);
1968
- };
1969
-
1970
- /**
1971
- * The key-down event for the ediable-div in the td-field. Check if the the div
1972
- * is empty and insert an &nbsp. Furthermore if cells are selected, unselect
1973
- * them.
1974
- *
1975
- * @param jqEvent
1976
- * the jquery-event object
1977
- * @return void
1978
- */
1979
- GENTICS.Aloha.Table.Cell.prototype.editableKeyDown = function(jqEvent) {
1980
- this.checkForEmptyEvent(jqEvent);
1981
- if (!jqEvent.ctrlKey && !jqEvent.shiftKey) {
1982
- if (GENTICS.Aloha.TableHelper.selectedCells.length > 0 && GENTICS.Aloha.TableHelper.selectedCells[0].length > 0) {
1983
- GENTICS.Aloha.TableHelper.selectedCells[0][0].firstChild.focus();
1984
- GENTICS.Aloha.TableHelper.unselectCells();
1985
- jqEvent.stopPropagation();
1986
- }
1987
- }else if(jqEvent.shiftKey && GENTICS.Aloha.TableHelper.selectedCells.length > 0){
1988
- var KEYCODE_ARROWLEFT = 37;
1989
- var KEYCODE_ARROWUP = 38;
1990
- var KEYCODE_ARROWRIGHT = 39;
1991
- var KEYCODE_ARROWDOWN = 40;
1992
- switch (GENTICS.Aloha.TableHelper.selectionType) {
1993
- case 'row':
1994
- switch(jqEvent.keyCode) {
1995
- case KEYCODE_ARROWUP:
1996
- var firstSelectedRow = GENTICS.Aloha.TableHelper.selectedCells[0][0].parentNode.rowIndex;
1997
- if (firstSelectedRow > 1) {
1998
- this.tableObj.rowsToSelect.push(firstSelectedRow - 1);
1999
- }
2000
- break;
2001
- case KEYCODE_ARROWDOWN:
2002
- var lastRowIndex = GENTICS.Aloha.TableHelper.selectedCells.length - 1;
2003
- var lastSelectedRow = GENTICS.Aloha.TableHelper.selectedCells[lastRowIndex][0].parentNode.rowIndex;
2004
- if (lastSelectedRow < this.tableObj.numRows) {
2005
- this.tableObj.rowsToSelect.push(lastSelectedRow + 1);
2006
- }
2007
- break;
2008
- }
2009
- this.tableObj.selectRows();
2010
-
2011
- break;
2012
- case 'col':
2013
- switch(jqEvent.keyCode) {
2014
- case KEYCODE_ARROWLEFT:
2015
- var firstColSelected = GENTICS.Aloha.TableHelper.selectedCells[0][0].cellIndex;
2016
- if (firstColSelected > 1) {
2017
- this.tableObj.columnsToSelect.push(firstColSelected - 1);
2018
- }
2019
- break;
2020
- case KEYCODE_ARROWRIGHT:
2021
- var lastColIndex = GENTICS.Aloha.TableHelper.selectedCells[0].length - 1;
2022
- var lastColSelected = GENTICS.Aloha.TableHelper.selectedCells[0][lastColIndex].cellIndex;
2023
- if (lastColSelected < this.tableObj.numCols) {
2024
- this.tableObj.columnsToSelect.push(lastColSelected + 1);
2025
- }
2026
- break;
2027
- }
2028
- this.tableObj.selectColumns();
2029
-
2030
- break;
2031
- }
2032
- jqEvent.stopPropagation();
2033
- jqEvent.preventDefault();
2034
- return false;
2035
- }
2036
- };
2037
-
2038
- /**
2039
- * The custom keyup event for a table-cell Checks if the cell is empty and
2040
- * inserts a space (\u00a0)
2041
- *
2042
- * @param e
2043
- * the event object which is given by jquery
2044
- * @return void
2045
- */
2046
- GENTICS.Aloha.Table.Cell.prototype.checkForEmptyEvent = function(jqEvent) {
2047
- // get the editable contents
2048
- var text = this.wrapper.text();
2049
-
2050
- // if empty insert a blank space and blur and focus the wrapper
2051
- if (text == ''){
2052
- this.wrapper.text('\u00a0');
2053
- this.wrapper.get(0).blur();
2054
- this.wrapper.get(0).focus();
2055
- }
2056
- };
2057
- /* -- END METHODS -- */
2058
-
2059
-
2060
- /**************************************
2061
- +---------------------------------+
2062
- | GENTICS.Aloha.Table.CreateLayer |
2063
- +---------------------------------+
2064
- ***************************************/
2065
- /**
2066
- * Dummy initialize of the CreateLayer object
2067
- */
2068
- GENTICS.Aloha.Table.CreateLayer = function(){};
2069
-
2070
- /* -- ATTRIBUTES -- */
2071
- /**
2072
- * Internal configuration of the create-table panel
2073
- */
2074
- GENTICS.Aloha.Table.CreateLayer.prototype.parameters = {
2075
- elemId: 'GENTICS_Aloha_SimpleTable_createLayer', // id of the create-table panel
2076
- className: 'GENTICS_Table_Createdialog', // class-name of the create-table panel
2077
- numX: 10, // Number of cols in the create-layer
2078
- numY: 10, // Number of rows in the create-layer vertically
2079
- layer: undefined, // Attribute holding the create-layer
2080
- target: undefined // the clicktarget which was clicked on (mostly the button of the floatingmenu)
2081
- };
2082
-
2083
- /**
2084
- * The configuration-object for the implementer of the plugin. All keys of
2085
- * the "parameters" object could be overwritten within this object and will
2086
- * simply be used instead.
2087
- */
2088
- GENTICS.Aloha.Table.CreateLayer.prototype.config = new Object();
2089
-
2090
- /**
2091
- * Flag wether the CreateLayer is currently visble or not
2092
- */
2093
- GENTICS.Aloha.Table.CreateLayer.prototype.visible = false;
2094
- /* -- END ATTRIBUTES -- */
2095
-
2096
- /* -- METHODS -- */
2097
- /**
2098
- * This function checks if there is an create-table-layer. If no layer exists, it creates one and puts it into the configuration.
2099
- * If the layer was already created it sets the position of the panel and shows it.
2100
- *
2101
- * @return void
2102
- */
2103
- GENTICS.Aloha.Table.CreateLayer.prototype.show = function(){
2104
- var layer = this.get('layer');
2105
-
2106
- // create the panel if the layer doesn't exist
2107
- if (layer == null) {
2108
- this.create();
2109
- }else {
2110
- // or reposition, cleanup and show the layer
2111
- this.setPosition(layer);
2112
- layer.find('td').removeClass('hover');
2113
- layer.show();
2114
- }
2115
- this.visible = true;
2116
- };
2117
- /**
2118
- * Creates the div-layer which holds a table with the given number of rows and cols.
2119
- * It sets click and mouseover-events to the table data fields
2120
- *
2121
- * @return void
2122
- */
2123
- GENTICS.Aloha.Table.CreateLayer.prototype.create = function () {
2124
- var that = this;
2125
- var layer = jQuery('<div></div>');
2126
- layer.id = this.get('elemId');
2127
- layer.addClass(this.get('className'));
2128
-
2129
- var table = jQuery('<table></table>');
2130
- table.css('width', (this.get('numX') + 6) * 15);
2131
- var tr;
2132
- var td;
2133
-
2134
- for (var i = 0; i < this.get('numY'); i++) {
2135
- tr = jQuery('<tr></tr>');
2136
-
2137
- for (var j = 0; j < this.get('numX'); j++) {
2138
- td = jQuery('<td>\u00a0</td>');
2139
-
2140
- if (i == 0 && j == 0) {
2141
- td.addClass('hover');
2142
- }
2143
-
2144
- td.bind('mouseover', {rowId: i, colId: j}, function(e) {
2145
- that.handleMouseOver(e, table);
2146
- });
2147
-
2148
- td.bind('click', {rowId: i, colId: j}, function(e){
2149
- var rows = e.data.rowId + 1;
2150
- var cols = e.data.colId + 1;
2151
-
2152
- GENTICS.Aloha.SimpleTablePlugin.createTable(cols, rows);
2153
- that.hide();
2154
- });
2155
-
2156
- tr.append(td);
2157
- }
2158
- table.append(tr);
2159
- }
2160
- layer.append(table);
2161
-
2162
- // set attributes
2163
- this.set('layer', layer);
2164
- this.setPosition();
2165
-
2166
- // stop bubbling the click on the create-dialog up to the body event
2167
- layer.bind('click', function(e) {
2168
- e.stopPropagation();
2169
- });
2170
-
2171
- // append layer to body and
2172
- // hide the create layer if user clicks anywhere in the body
2173
- jQuery('body').append(layer).bind('click', function(e) {
2174
- if (e.target != that.get('target') && that.visible) {
2175
- that.hide();
2176
- }
2177
- });
2178
- };
2179
-
2180
- /**
2181
- * handles the mose over state for a cell
2182
- * @param e event object
2183
- * @param table the aeffected table
2184
- * @return void
2185
- */
2186
- GENTICS.Aloha.Table.CreateLayer.prototype.handleMouseOver = function(e, table) {
2187
- var rowId = e.data.rowId;
2188
- var colId = e.data.colId;
2189
- var innerRows = table.find('tr');
2190
-
2191
- for (var n = 0; n <= innerRows.length; n++) {
2192
- var innerCells = jQuery(innerRows[n]).find('td');
2193
-
2194
- for (var k = 0; k <= innerCells.length; k++) {
2195
- if (n <= rowId && k <= colId) {
2196
- jQuery(innerCells[k]).addClass('hover');
2197
- } else {
2198
- jQuery(innerCells[k]).removeClass('hover');
2199
- }
2200
- }
2201
- }
2202
- };
2203
-
2204
- /**
2205
- * Sets the "left" and "top" style-attributes according to the clicked target-button
2206
- *
2207
- * @return void
2208
- */
2209
- GENTICS.Aloha.Table.CreateLayer.prototype.setPosition = function() {
2210
- var targetObj = jQuery(this.get('target'));
2211
- var pos = targetObj.offset();
2212
- this.get('layer').css('left', pos.left + 'px');
2213
- this.get('layer').css('top', (pos.top + targetObj.height()) + 'px');
2214
- };
2215
-
2216
-
2217
- /**
2218
- * Hides the create-table panel width the jQuery-method hide()
2219
- *
2220
- * @see jQuery().hide()
2221
- * @return void
2222
- */
2223
- GENTICS.Aloha.Table.CreateLayer.prototype.hide = function() {
2224
- this.get('layer').hide();
2225
- this.visible = false;
2226
- };
2227
-
2228
- /**
2229
- * The "get"-method returns the value of the given key. First it searches in the
2230
- * config for the property. If there is no property with the given name in the
2231
- * "config"-object it returns the entry associated with in the parameters-object
2232
- *
2233
- * @param property
2234
- * @return void
2235
- */
2236
- GENTICS.Aloha.Table.CreateLayer.prototype.get = function(property) {
2237
- // return param from the config
2238
- if (this.config[property]) {
2239
- return this.config[property];
2240
- }
2241
- // if config-param was not found return param from the parameters-object
2242
- if (this.parameters[property]) {
2243
- return this.parameters[property];
2244
- }
2245
- return undefined;
2246
- };
2247
-
2248
- /**
2249
- * The "set"-method takes a key and a value. It checks if there is a key-value
2250
- * pair in the config-object. If so it saves the data in the config-object. If
2251
- * not it saves the data in the parameters-object.
2252
- *
2253
- * @param key
2254
- * the key which should be set
2255
- * @param value
2256
- * the value which should be set for the associated key
2257
- */
2258
- GENTICS.Aloha.Table.CreateLayer.prototype.set = function (key, value) {
2259
- // if the key already exists in the config-object, set it to the config-object
2260
- if (this.config[key]) {
2261
- this.config[key] = value;
2262
-
2263
- // otherwise "add" it to the parameters-object
2264
- }else{
2265
- this.parameters[key] = value;
2266
- }
2267
- };
2268
- /* -- END METHODS -- */
2269
-
2270
-
2271
-
2272
- /********************************
2273
- +---------------------------+
2274
- | GENTICS.Aloha.TableHelper |
2275
- +---------------------------+
2276
- *********************************/
2277
- /**
2278
- * The TableHelper object is a helper-object which consists of static/global attributes and functions
2279
- */
2280
- GENTICS.Aloha.TableHelper = function(){};
2281
-
2282
- /* -- ATTRIBUTES -- */
2283
- /**
2284
- * Gives the type of the cell-selection
2285
- * possible values are "row" or "col"
2286
- */
2287
- GENTICS.Aloha.TableHelper.prototype.selectionType = undefined;
2288
-
2289
- /**
2290
- * Holds all currently selected table cells as an array of DOM "td" representations
2291
- */
2292
- GENTICS.Aloha.TableHelper.prototype.selectedCells = new Array();
2293
- /* -- END ATTRIBUTES -- */
2294
-
2295
- /* -- METHODS -- */
2296
- /**
2297
- * This method removes the "selected" class from all selected cells
2298
- *
2299
- * @return void
2300
- */
2301
- GENTICS.Aloha.TableHelper.prototype.unselectCells = function(){
2302
- if (this.selectedCells.length > 0) {
2303
- for (var i = 0; i < this.selectedCells.length; i++) {
2304
- jQuery(this.selectedCells[i]).removeClass(GENTICS.Aloha.SimpleTablePlugin.get('classCellSelected'));
2305
- }
2306
- this.selectedCells = new Array();
2307
- this.selectionType = undefined;
2308
- }
2309
- };
2310
-
2311
- GENTICS.Aloha.TableHelper.prototype.getNewTableID = function() {
2312
- var idPrefix = 'GENTICS_Table_';
2313
- var factor = 1000000;
2314
- for (this.tableCounter; true; this.tableCounter ++) {
2315
- var id = idPrefix + (Math.ceil(Math.random() * factor));
2316
- // fill up the id with zeros
2317
- for (var j = id.length; j < idPrefix.length + factor.toString().length; j++) {
2318
- id += '0';
2319
- }
2320
- if (!jQuery('#' + id).length) {
2321
- return id;
2322
- }
2323
- }
2324
- };
2325
- /* -- END METHODS -- */
2326
-
2327
- /**
2328
- * Initialize a new Object from the same object to get access to the prototype methods
2329
- */
2330
- GENTICS.Aloha.TableHelper = new GENTICS.Aloha.TableHelper();