wakame-vdc-webui 10.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. data/INSTALL.txt +21 -0
  2. data/LICENSE +202 -0
  3. data/NOTICE +1 -0
  4. data/README +256 -0
  5. data/Rakefile +42 -0
  6. data/app/controllers/accounts_controller.rb +15 -0
  7. data/app/controllers/application_controller.rb +5 -0
  8. data/app/controllers/dialog_controller.rb +80 -0
  9. data/app/controllers/home_controller.rb +5 -0
  10. data/app/controllers/host_pools_controller.rb +26 -0
  11. data/app/controllers/images_controller.rb +28 -0
  12. data/app/controllers/information_controller.rb +10 -0
  13. data/app/controllers/instances_controller.rb +59 -0
  14. data/app/controllers/keypairs_controller.rb +64 -0
  15. data/app/controllers/security_groups_controller.rb +59 -0
  16. data/app/controllers/sessions_controller.rb +25 -0
  17. data/app/controllers/snapshots_controller.rb +48 -0
  18. data/app/controllers/storage_pools_controller.rb +27 -0
  19. data/app/controllers/users_controller.rb +3 -0
  20. data/app/controllers/volumes_controller.rb +86 -0
  21. data/app/helpers/accounts_helper.rb +2 -0
  22. data/app/helpers/application_helper.rb +23 -0
  23. data/app/helpers/dialog_helper.rb +2 -0
  24. data/app/helpers/home_helper.rb +2 -0
  25. data/app/helpers/host_pools_helper.rb +2 -0
  26. data/app/helpers/images_helper.rb +2 -0
  27. data/app/helpers/information_helper.rb +2 -0
  28. data/app/helpers/instances_helper.rb +2 -0
  29. data/app/helpers/keypairs_helper.rb +2 -0
  30. data/app/helpers/security_groups_helper.rb +2 -0
  31. data/app/helpers/sessions_helper.rb +2 -0
  32. data/app/helpers/snapshots_helper.rb +2 -0
  33. data/app/helpers/storage_pools_helper.rb +2 -0
  34. data/app/helpers/users_helper.rb +2 -0
  35. data/app/helpers/volumes_helper.rb +2 -0
  36. data/app/models/account.rb +104 -0
  37. data/app/models/authz.rb +102 -0
  38. data/app/models/base_new.rb +311 -0
  39. data/app/models/dcmgr_resource/account.rb +5 -0
  40. data/app/models/dcmgr_resource/base.rb +51 -0
  41. data/app/models/dcmgr_resource/host_pool.rb +11 -0
  42. data/app/models/dcmgr_resource/image.rb +11 -0
  43. data/app/models/dcmgr_resource/instance.rb +37 -0
  44. data/app/models/dcmgr_resource/mock.rb +15 -0
  45. data/app/models/dcmgr_resource/netfilter_group.rb +29 -0
  46. data/app/models/dcmgr_resource/ssh_key_pair.rb +25 -0
  47. data/app/models/dcmgr_resource/storage_pool.rb +11 -0
  48. data/app/models/dcmgr_resource/volume.rb +48 -0
  49. data/app/models/dcmgr_resource/volume_snapshot.rb +35 -0
  50. data/app/models/information.rb +9 -0
  51. data/app/models/schema.rb +51 -0
  52. data/app/models/tag.rb +121 -0
  53. data/app/models/tag_mapping.rb +25 -0
  54. data/app/models/user.rb +46 -0
  55. data/app/views/accounts/index.html.erb +68 -0
  56. data/app/views/dialog/attach_volume.html.erb +13 -0
  57. data/app/views/dialog/create_and_edit_security_group.html.erb +32 -0
  58. data/app/views/dialog/create_snapshot.html.erb +7 -0
  59. data/app/views/dialog/create_ssh_keypair.html.erb +15 -0
  60. data/app/views/dialog/create_volume.html.erb +18 -0
  61. data/app/views/dialog/create_volume_from_snapshot.html.erb +7 -0
  62. data/app/views/dialog/delete_security_group.html.erb +4 -0
  63. data/app/views/dialog/delete_snapshot.html.erb +7 -0
  64. data/app/views/dialog/delete_ssh_keypair.html.erb +4 -0
  65. data/app/views/dialog/delete_volume.html.erb +7 -0
  66. data/app/views/dialog/detach_volume.html.erb +7 -0
  67. data/app/views/dialog/launch_instance.html.erb +70 -0
  68. data/app/views/dialog/reboot_instances.html.erb +7 -0
  69. data/app/views/dialog/start_instances.html.erb +8 -0
  70. data/app/views/dialog/stop_instances.html.erb +7 -0
  71. data/app/views/dialog/terminate_instances.html.erb +7 -0
  72. data/app/views/home/index.html.erb +55 -0
  73. data/app/views/host_pools/index.html.erb +103 -0
  74. data/app/views/images/index.html.erb +126 -0
  75. data/app/views/information/index.html.erb +25 -0
  76. data/app/views/instances/index.html.erb +134 -0
  77. data/app/views/keypairs/index.html.erb +104 -0
  78. data/app/views/layouts/_footer.html.erb +4 -0
  79. data/app/views/layouts/_header.html.erb +14 -0
  80. data/app/views/layouts/_informationarea.html.erb +18 -0
  81. data/app/views/layouts/_login_header.erb +4 -0
  82. data/app/views/layouts/_service_health.erb +27 -0
  83. data/app/views/layouts/_sidemenu.html.erb +58 -0
  84. data/app/views/layouts/application.html.erb +34 -0
  85. data/app/views/layouts/login.html.erb +25 -0
  86. data/app/views/security_groups/index.html.erb +114 -0
  87. data/app/views/sessions/new.html.erb +27 -0
  88. data/app/views/snapshots/index.html.erb +110 -0
  89. data/app/views/storage_pools/index.html.erb +98 -0
  90. data/app/views/volumes/index.html.erb +117 -0
  91. data/config.ru +4 -0
  92. data/config/application.rb +48 -0
  93. data/config/boot.rb +13 -0
  94. data/config/database.yml +20 -0
  95. data/config/environment.rb +5 -0
  96. data/config/environments/development.rb +28 -0
  97. data/config/environments/production.rb +49 -0
  98. data/config/environments/test.rb +35 -0
  99. data/config/initializers/backtrace_silencers.rb +7 -0
  100. data/config/initializers/dcmgr_gui.rb +14 -0
  101. data/config/initializers/inflections.rb +10 -0
  102. data/config/initializers/mime_types.rb +5 -0
  103. data/config/initializers/secret_token.rb +7 -0
  104. data/config/initializers/session_store.rb +8 -0
  105. data/config/locales/en.yml +5 -0
  106. data/config/routes.rb +109 -0
  107. data/db/seeds.rb +7 -0
  108. data/extras/authentication.rb +94 -0
  109. data/extras/util.rb +5 -0
  110. data/lib/tasks/dcmgr_gui.rake +51 -0
  111. data/public/404.html +26 -0
  112. data/public/422.html +26 -0
  113. data/public/500.html +26 -0
  114. data/public/favicon.ico +0 -0
  115. data/public/images/app_active.gif +0 -0
  116. data/public/images/app_passive.gif +0 -0
  117. data/public/images/body_bg.gif +0 -0
  118. data/public/images/btn_change.gif +0 -0
  119. data/public/images/btn_create_security_group.gif +0 -0
  120. data/public/images/btn_create_snapshot.gif +0 -0
  121. data/public/images/btn_create_volume.gif +0 -0
  122. data/public/images/btn_createkey.gif +0 -0
  123. data/public/images/btn_de_register.gif +0 -0
  124. data/public/images/btn_delete_security_group.gif +0 -0
  125. data/public/images/btn_delete_snapshot.gif +0 -0
  126. data/public/images/btn_delete_volume.gif +0 -0
  127. data/public/images/btn_deletekey.gif +0 -0
  128. data/public/images/btn_healthdetail.gif +0 -0
  129. data/public/images/btn_hide.gif +0 -0
  130. data/public/images/btn_launch.gif +0 -0
  131. data/public/images/btn_next.gif +0 -0
  132. data/public/images/btn_prev.gif +0 -0
  133. data/public/images/btn_refresh.gif +0 -0
  134. data/public/images/btn_register_new_ami.gif +0 -0
  135. data/public/images/btn_savechange.gif +0 -0
  136. data/public/images/btn_show.gif +0 -0
  137. data/public/images/btn_show_accesskey.png +0 -0
  138. data/public/images/bup_btn_healthdetail.gif +0 -0
  139. data/public/images/bup_btn_refresh.gif +0 -0
  140. data/public/images/clear.gif +0 -0
  141. data/public/images/content_bg.png +0 -0
  142. data/public/images/content_foot_bg.gif +0 -0
  143. data/public/images/content_head_bg.gif +0 -0
  144. data/public/images/footer_bg.gif +0 -0
  145. data/public/images/head_gradation_bg.gif +0 -0
  146. data/public/images/header_logo.gif +0 -0
  147. data/public/images/icon_blockstore.gif +0 -0
  148. data/public/images/icon_caution.gif +0 -0
  149. data/public/images/icon_health.gif +0 -0
  150. data/public/images/icon_images.gif +0 -0
  151. data/public/images/icon_information.gif +0 -0
  152. data/public/images/icon_instances.gif +0 -0
  153. data/public/images/icon_resource.gif +0 -0
  154. data/public/images/icon_resource01.gif +0 -0
  155. data/public/images/icon_resource02.gif +0 -0
  156. data/public/images/icon_resource03.gif +0 -0
  157. data/public/images/icon_resource04.gif +0 -0
  158. data/public/images/icon_rss.gif +0 -0
  159. data/public/images/icon_security.gif +0 -0
  160. data/public/images/icon_service.gif +0 -0
  161. data/public/images/icon_service_stat.gif +0 -0
  162. data/public/images/icon_stop.gif +0 -0
  163. data/public/images/icon_summary.gif +0 -0
  164. data/public/images/icon_ttl_accskey.gif +0 -0
  165. data/public/images/icon_ttl_detail.gif +0 -0
  166. data/public/images/icon_ttl_instance.gif +0 -0
  167. data/public/images/icon_ttl_personal_inf.gif +0 -0
  168. data/public/images/infra_active.gif +0 -0
  169. data/public/images/infra_passive.gif +0 -0
  170. data/public/images/lastelement_bg.gif +0 -0
  171. data/public/images/lastelement_bg.png +0 -0
  172. data/public/images/listicon_useast.gif +0 -0
  173. data/public/images/loader_ball.gif +0 -0
  174. data/public/images/loader_boxes.gif +0 -0
  175. data/public/images/loading.gif +0 -0
  176. data/public/images/mainarea_bottom_bg.gif +0 -0
  177. data/public/images/mainarea_content_bg.gif +0 -0
  178. data/public/images/mainarea_h3_bg.gif +0 -0
  179. data/public/images/mainarea_wide_bottom_bg.gif +0 -0
  180. data/public/images/mainarea_wide_content_bg.gif +0 -0
  181. data/public/images/mainarea_wide_h3_bg.gif +0 -0
  182. data/public/images/menu_list_header.gif +0 -0
  183. data/public/images/menu_list_header_current.gif +0 -0
  184. data/public/images/plat_active.gif +0 -0
  185. data/public/images/plat_passive.gif +0 -0
  186. data/public/images/regionselect_bg.gif +0 -0
  187. data/public/images/select_bg_126.gif +0 -0
  188. data/public/images/select_bg_139.gif +0 -0
  189. data/public/images/sidemenu_bg.gif +0 -0
  190. data/public/images/sidemenu_bottom.gif +0 -0
  191. data/public/images/sidemenu_top.gif +0 -0
  192. data/public/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  193. data/public/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  194. data/public/images/ui-bg_flat_10_000000_40x100.png +0 -0
  195. data/public/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  196. data/public/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  197. data/public/images/ui-bg_glass_55_fcf0ba_1x400.png +0 -0
  198. data/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  199. data/public/images/ui-bg_gloss-wave_100_ece8da_500x100.png +0 -0
  200. data/public/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  201. data/public/images/ui-bg_highlight-hard_100_f5f3e5_1x100.png +0 -0
  202. data/public/images/ui-bg_highlight-hard_100_fafaf4_1x100.png +0 -0
  203. data/public/images/ui-bg_highlight-hard_15_459e00_1x100.png +0 -0
  204. data/public/images/ui-bg_highlight-hard_95_cccccc_1x100.png +0 -0
  205. data/public/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  206. data/public/images/ui-bg_highlight-soft_25_67b021_1x100.png +0 -0
  207. data/public/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  208. data/public/images/ui-bg_highlight-soft_95_ffedad_1x100.png +0 -0
  209. data/public/images/ui-bg_inset-soft_15_2b2922_1x100.png +0 -0
  210. data/public/images/ui-icons_222222_256x240.png +0 -0
  211. data/public/images/ui-icons_228ef1_256x240.png +0 -0
  212. data/public/images/ui-icons_808080_256x240.png +0 -0
  213. data/public/images/ui-icons_847e71_256x240.png +0 -0
  214. data/public/images/ui-icons_8dc262_256x240.png +0 -0
  215. data/public/images/ui-icons_cd0a0a_256x240.png +0 -0
  216. data/public/images/ui-icons_eeeeee_256x240.png +0 -0
  217. data/public/images/ui-icons_ef8c08_256x240.png +0 -0
  218. data/public/images/ui-icons_ffd27a_256x240.png +0 -0
  219. data/public/images/ui-icons_ffffff_256x240.png +0 -0
  220. data/public/images/vtip_arrow.png +0 -0
  221. data/public/javascripts/controls.js +965 -0
  222. data/public/javascripts/dcmgr_gui/application.js +91 -0
  223. data/public/javascripts/dcmgr_gui/core.js +539 -0
  224. data/public/javascripts/dcmgr_gui/dashboard_panel.js +34 -0
  225. data/public/javascripts/dcmgr_gui/host_pool_panel.js +83 -0
  226. data/public/javascripts/dcmgr_gui/image_panel.js +242 -0
  227. data/public/javascripts/dcmgr_gui/instance_panel.js +197 -0
  228. data/public/javascripts/dcmgr_gui/security_group_panel.js +196 -0
  229. data/public/javascripts/dcmgr_gui/snapshot_panel.js +168 -0
  230. data/public/javascripts/dcmgr_gui/sshkeypair_panel.js +161 -0
  231. data/public/javascripts/dcmgr_gui/storage_pool_panel.js +99 -0
  232. data/public/javascripts/dcmgr_gui/volume_panel.js +311 -0
  233. data/public/javascripts/dragdrop.js +974 -0
  234. data/public/javascripts/effects.js +1123 -0
  235. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  236. data/public/javascripts/jquery-ui-1.8.4.custom.min.js +763 -0
  237. data/public/javascripts/jquery.loadmask.min.js +10 -0
  238. data/public/javascripts/jquery.tmpl.js +486 -0
  239. data/public/javascripts/jsdeferred.jquery.js +385 -0
  240. data/public/javascripts/prototype.js +6001 -0
  241. data/public/javascripts/rails.js +175 -0
  242. data/public/robots.txt +5 -0
  243. data/public/stylesheets/common.css +1236 -0
  244. data/public/stylesheets/dialog.css +67 -0
  245. data/public/stylesheets/jquery-ui-1.8.4.custom.css +572 -0
  246. data/public/stylesheets/jquery.loadmask.css +40 -0
  247. data/public/stylesheets/reset.css +71 -0
  248. data/public/stylesheets/style.css +7 -0
  249. data/public/stylesheets/vtip.css +28 -0
  250. data/script/rails +6 -0
  251. data/test/functional/accounts_controller_test.rb +8 -0
  252. data/test/functional/dialog_controller_test.rb +8 -0
  253. data/test/functional/home_controller_test.rb +8 -0
  254. data/test/functional/host_pools_controller_test.rb +8 -0
  255. data/test/functional/images_controller_test.rb +8 -0
  256. data/test/functional/information_controller_test.rb +8 -0
  257. data/test/functional/instances_controller_test.rb +8 -0
  258. data/test/functional/keypairs_controller_test.rb +8 -0
  259. data/test/functional/security_groups_controller_test.rb +8 -0
  260. data/test/functional/sessions_controller_test.rb +8 -0
  261. data/test/functional/snapshots_controller_test.rb +8 -0
  262. data/test/functional/storage_pools_controller_test.rb +8 -0
  263. data/test/functional/users_controller_test.rb +8 -0
  264. data/test/functional/volumes_controller_test.rb +8 -0
  265. data/test/performance/browsing_test.rb +9 -0
  266. data/test/test_helper.rb +13 -0
  267. data/test/unit/helpers/accounts_helper_test.rb +4 -0
  268. data/test/unit/helpers/dialog_helper_test.rb +4 -0
  269. data/test/unit/helpers/home_helper_test.rb +4 -0
  270. data/test/unit/helpers/host_pools_helper_test.rb +4 -0
  271. data/test/unit/helpers/images_helper_test.rb +4 -0
  272. data/test/unit/helpers/information_helper_test.rb +4 -0
  273. data/test/unit/helpers/instances_helper_test.rb +4 -0
  274. data/test/unit/helpers/keypairs_helper_test.rb +4 -0
  275. data/test/unit/helpers/security_groups_helper_test.rb +4 -0
  276. data/test/unit/helpers/sessions_helper_test.rb +4 -0
  277. data/test/unit/helpers/snapshots_helper_test.rb +4 -0
  278. data/test/unit/helpers/storage_pools_helper_test.rb +4 -0
  279. data/test/unit/helpers/users_helper_test.rb +4 -0
  280. data/test/unit/helpers/volumes_helper_test.rb +4 -0
  281. metadata +399 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) 2009 Sergiy Kovalchuk (serg472@gmail.com)
3
+ *
4
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
5
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
6
+ *
7
+ * Following code is based on Element.mask() implementation from ExtJS framework (http://extjs.com/)
8
+ *
9
+ */
10
+ (function(a){a.fn.mask=function(c,b){a(this).each(function(){if(b!==undefined&&b>0){var d=a(this);d.data("_mask_timeout",setTimeout(function(){a.maskElement(d,c)},b))}else{a.maskElement(a(this),c)}})};a.fn.unmask=function(){a(this).each(function(){a.unmaskElement(a(this))})};a.fn.isMasked=function(){return this.hasClass("masked")};a.maskElement=function(d,c){if(d.data("_mask_timeout")!==undefined){clearTimeout(d.data("_mask_timeout"));d.removeData("_mask_timeout")}if(d.isMasked()){a.unmaskElement(d)}if(d.css("position")=="static"){d.addClass("masked-relative")}d.addClass("masked");var e=a('<div class="loadmask"></div>');if(navigator.userAgent.toLowerCase().indexOf("msie")>-1){e.height(d.height()+parseInt(d.css("padding-top"))+parseInt(d.css("padding-bottom")));e.width(d.width()+parseInt(d.css("padding-left"))+parseInt(d.css("padding-right")))}if(navigator.userAgent.toLowerCase().indexOf("msie 6")>-1){d.find("select").addClass("masked-hidden")}d.append(e);if(c!==undefined){var b=a('<div class="loadmask-msg" style="display:none;"></div>');b.append("<div>"+c+"</div>");d.append(b);b.css("top",Math.round(d.height()/2-(b.height()-parseInt(b.css("padding-top"))-parseInt(b.css("padding-bottom")))/2)+"px");b.css("left",Math.round(d.width()/2-(b.width()-parseInt(b.css("padding-left"))-parseInt(b.css("padding-right")))/2)+"px");b.show()}};a.unmaskElement=function(b){if(b.data("_mask_timeout")!==undefined){clearTimeout(b.data("_mask_timeout"));b.removeData("_mask_timeout")}b.find(".loadmask-msg,.loadmask").remove();b.removeClass("masked");b.removeClass("masked-relative");b.find("select").removeClass("masked-hidden")}})(jQuery);
@@ -0,0 +1,486 @@
1
+ /*
2
+ * jQuery Templating Plugin
3
+ * Copyright 2010, John Resig
4
+ * Dual licensed under the MIT or GPL Version 2 licenses.
5
+ */
6
+ (function( jQuery, undefined ){
7
+ var oldManip = jQuery.fn.domManip, tmplItmAtt = "_tmplitem", htmlExpr = /^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
8
+ newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = [];
9
+
10
+ function newTmplItem( options, parentItem, fn, data ) {
11
+ // Returns a template item data structure for a new rendered instance of a template (a 'template item').
12
+ // The content field is a hierarchical array of strings and nested items (to be
13
+ // removed and replaced by nodes field of dom elements, once inserted in DOM).
14
+ var newItem = {
15
+ data: data || (parentItem ? parentItem.data : {}),
16
+ _wrap: parentItem ? parentItem._wrap : null,
17
+ tmpl: null,
18
+ parent: parentItem || null,
19
+ nodes: [],
20
+ calls: tiCalls,
21
+ nest: tiNest,
22
+ wrap: tiWrap,
23
+ html: tiHtml,
24
+ update: tiUpdate
25
+ };
26
+ if ( options ) {
27
+ jQuery.extend( newItem, options, { nodes: [], parent: parentItem } );
28
+ }
29
+ if ( fn ) {
30
+ // Build the hierarchical content to be used during insertion into DOM
31
+ newItem.tmpl = fn;
32
+ newItem._ctnt = newItem._ctnt || newItem.tmpl( jQuery, newItem );
33
+ newItem.key = ++itemKey;
34
+ // Keep track of new template item, until it is stored as jQuery Data on DOM element
35
+ (stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem;
36
+ }
37
+ return newItem;
38
+ }
39
+
40
+ // Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core).
41
+ jQuery.each({
42
+ appendTo: "append",
43
+ prependTo: "prepend",
44
+ insertBefore: "before",
45
+ insertAfter: "after",
46
+ replaceAll: "replaceWith"
47
+ }, function( name, original ) {
48
+ jQuery.fn[ name ] = function( selector ) {
49
+ var ret = [], insert = jQuery( selector ), elems, i, l, tmplItems,
50
+ parent = this.length === 1 && this[0].parentNode;
51
+
52
+ appendToTmplItems = newTmplItems || {};
53
+ if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
54
+ insert[ original ]( this[0] );
55
+ ret = this;
56
+ } else {
57
+ for ( i = 0, l = insert.length; i < l; i++ ) {
58
+ cloneIndex = i;
59
+ elems = (i > 0 ? this.clone(true) : this).get();
60
+ jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
61
+ ret = ret.concat( elems );
62
+ }
63
+ cloneIndex = 0;
64
+ ret = this.pushStack( ret, name, insert.selector );
65
+ }
66
+ tmplItems = appendToTmplItems;
67
+ appendToTmplItems = null;
68
+ jQuery.tmpl.complete( tmplItems );
69
+ return ret;
70
+ };
71
+ });
72
+
73
+ jQuery.fn.extend({
74
+ // Use first wrapped element as template markup.
75
+ // Return wrapped set of template items, obtained by rendering template against data.
76
+ tmpl: function( data, options, parentItem ) {
77
+ return jQuery.tmpl( this[0], data, options, parentItem );
78
+ },
79
+
80
+ // Find which rendered template item the first wrapped DOM element belongs to
81
+ tmplItem: function() {
82
+ return jQuery.tmplItem( this[0] );
83
+ },
84
+
85
+ // Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
86
+ template: function( name ) {
87
+ return jQuery.template( name, this[0] );
88
+ },
89
+
90
+ domManip: function( args, table, callback, options ) {
91
+ // This appears to be a bug in the appendTo, etc. implementation
92
+ // it should be doing .call() instead of .apply(). See #6227
93
+ if ( args[0] && args[0].nodeType ) {
94
+ var dmArgs = jQuery.makeArray( arguments ), argsLength = args.length, i = 0, tmplItem;
95
+ while ( i < argsLength && !(tmplItem = jQuery.data( args[i++], "tmplItem" ))) {}
96
+ if ( argsLength > 1 ) {
97
+ dmArgs[0] = [jQuery.makeArray( args )];
98
+ }
99
+ if ( tmplItem && cloneIndex ) {
100
+ dmArgs[2] = function( fragClone ) {
101
+ // Handler called by oldManip when rendered template has been inserted into DOM.
102
+ jQuery.tmpl.afterManip( this, fragClone, callback );
103
+ };
104
+ }
105
+ oldManip.apply( this, dmArgs );
106
+ } else {
107
+ oldManip.apply( this, arguments );
108
+ }
109
+ cloneIndex = 0;
110
+ if ( !appendToTmplItems ) {
111
+ jQuery.tmpl.complete( newTmplItems );
112
+ }
113
+ return this;
114
+ }
115
+ });
116
+
117
+ jQuery.extend({
118
+ // Return wrapped set of template items, obtained by rendering template against data.
119
+ tmpl: function( tmpl, data, options, parentItem ) {
120
+ var ret, topLevel = !parentItem;
121
+ if ( topLevel ) {
122
+ // This is a top-level tmpl call (not from a nested template using {{tmpl}})
123
+ parentItem = topTmplItem;
124
+ tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
125
+ wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
126
+ } else if ( !tmpl ) {
127
+ // The template item is already associated with DOM - this is a refresh.
128
+ // Re-evaluate rendered template for the parentItem
129
+ tmpl = parentItem.tmpl;
130
+ newTmplItems[parentItem.key] = parentItem;
131
+ parentItem.nodes = [];
132
+ if ( parentItem.wrapped ) {
133
+ updateWrapped( parentItem, parentItem.wrapped );
134
+ }
135
+ // Rebuild, without creating a new template item
136
+ return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
137
+ }
138
+ if ( !tmpl ) {
139
+ return []; // Could throw...
140
+ }
141
+ if ( typeof data === "function" ) {
142
+ data = data.call( parentItem || {} );
143
+ }
144
+ if ( options && options.wrapped ) {
145
+ updateWrapped( options, options.wrapped );
146
+ }
147
+ ret = jQuery.isArray( data ) ?
148
+ jQuery.map( data, function( dataItem ) {
149
+ return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
150
+ }) :
151
+ [ newTmplItem( options, parentItem, tmpl, data ) ];
152
+ return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
153
+ },
154
+
155
+ // Return rendered template item for an element.
156
+ tmplItem: function( elem ) {
157
+ var tmplItem;
158
+ if ( elem instanceof jQuery ) {
159
+ elem = elem[0];
160
+ }
161
+ while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
162
+ return tmplItem || topTmplItem;
163
+ },
164
+
165
+ // Set:
166
+ // Use $.template( name, tmpl ) to cache a named template,
167
+ // where tmpl is a template string, a script element or a jQuery instance wrapping a script element, etc.
168
+ // Use $( "selector" ).template( name ) to provide access by name to a script block template declaration.
169
+
170
+ // Get:
171
+ // Use $.template( name ) to access a cached template.
172
+ // Also $( selectorToScriptBlock ).template(), or $.template( null, templateString )
173
+ // will return the compiled template, without adding a name reference.
174
+ // If templateString includes at least one HTML tag, $.template( templateString ) is equivalent
175
+ // to $.template( null, templateString )
176
+ template: function( name, tmpl ) {
177
+ if (tmpl) {
178
+ // Compile template and associate with name
179
+ if ( typeof tmpl === "string" ) {
180
+ // This is an HTML string being passed directly in.
181
+ tmpl = buildTmplFn( tmpl )
182
+ } else if ( tmpl instanceof jQuery ) {
183
+ tmpl = tmpl[0] || {};
184
+ }
185
+ if ( tmpl.nodeType ) {
186
+ // If this is a template block, use cached copy, or generate tmpl function and cache.
187
+ tmpl = jQuery.data( tmpl, "tmpl" ) || jQuery.data( tmpl, "tmpl", buildTmplFn( tmpl.innerHTML ));
188
+ }
189
+ return typeof name === "string" ? (jQuery.template[name] = tmpl) : tmpl;
190
+ }
191
+ // Return named compiled template
192
+ return name ? (typeof name !== "string" ? jQuery.template( null, name ):
193
+ (jQuery.template[name] ||
194
+ // If not in map, treat as a selector. (If integrated with core, use quickExpr.exec)
195
+ jQuery.template( null, htmlExpr.test( name ) ? name : jQuery( name )))) : null;
196
+ },
197
+
198
+ encode: function( text ) {
199
+ // Do HTML encoding replacing < > & and ' and " by corresponding entities.
200
+ return ("" + text).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;");
201
+ }
202
+ });
203
+
204
+ jQuery.extend( jQuery.tmpl, {
205
+ tag: {
206
+ "tmpl": {
207
+ _default: { $2: "null" },
208
+ open: "if($notnull_1){_=_.concat($item.nest($1,$2));}"
209
+ // tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions)
210
+ // This means that {{tmpl foo}} treats foo as a template (which IS a function).
211
+ // Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}.
212
+ },
213
+ "wrap": {
214
+ _default: { $2: "null" },
215
+ open: "$item.calls(_,$1,$2);_=[];",
216
+ close: "call=$item.calls();_=call._.concat($item.wrap(call,_));"
217
+ },
218
+ "each": {
219
+ _default: { $2: "$index, $value" },
220
+ open: "if($notnull_1){$.each($1a,function($2){with(this){",
221
+ close: "}});}"
222
+ },
223
+ "if": {
224
+ open: "if(($notnull_1) && $1a){",
225
+ close: "}"
226
+ },
227
+ "else": {
228
+ _default: { $1: "true" },
229
+ open: "}else if(($notnull_1) && $1a){"
230
+ },
231
+ "html": {
232
+ // Unecoded expression evaluation.
233
+ open: "if($notnull_1){_.push($1a);}"
234
+ },
235
+ "=": {
236
+ // Encoded expression evaluation. Abbreviated form is ${}.
237
+ _default: { $1: "$data" },
238
+ open: "if($notnull_1){_.push($.encode($1a));}"
239
+ },
240
+ "!": {
241
+ // Comment tag. Skipped by parser
242
+ open: ""
243
+ }
244
+ },
245
+
246
+ // This stub can be overridden, e.g. in jquery.tmplPlus for providing rendered events
247
+ complete: function( items ) {
248
+ newTmplItems = {};
249
+ },
250
+
251
+ // Call this from code which overrides domManip, or equivalent
252
+ // Manage cloning/storing template items etc.
253
+ afterManip: function afterManip( elem, fragClone, callback ) {
254
+ // Provides cloned fragment ready for fixup prior to and after insertion into DOM
255
+ var content = fragClone.nodeType === 11 ?
256
+ jQuery.makeArray(fragClone.childNodes) :
257
+ fragClone.nodeType === 1 ? [fragClone] : [];
258
+
259
+ // Return fragment to original caller (e.g. append) for DOM insertion
260
+ callback.call( elem, fragClone );
261
+
262
+ // Fragment has been inserted:- Add inserted nodes to tmplItem data structure. Replace inserted element annotations by jQuery.data.
263
+ storeTmplItems( content );
264
+ cloneIndex++;
265
+ }
266
+ });
267
+
268
+ //========================== Private helper functions, used by code above ==========================
269
+
270
+ function build( tmplItem, nested, content ) {
271
+ // Convert hierarchical content into flat string array
272
+ // and finally return array of fragments ready for DOM insertion
273
+ var frag, ret = content ? jQuery.map( content, function( item ) {
274
+ return (typeof item === "string") ?
275
+ // Insert template item annotations, to be converted to jQuery.data( "tmplItem" ) when elems are inserted into DOM.
276
+ (tmplItem.key ? item.replace( /(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g, "$1 " + tmplItmAtt + "=\"" + tmplItem.key + "\" $2" ) : item) :
277
+ // This is a child template item. Build nested template.
278
+ build( item, tmplItem, item._ctnt );
279
+ }) :
280
+ // If content is not defined, insert tmplItem directly. Not a template item. May be a string, or a string array, e.g. from {{html $item.html()}}.
281
+ tmplItem;
282
+ if ( nested ) {
283
+ return ret;
284
+ }
285
+
286
+ // top-level template
287
+ ret = ret.join("");
288
+
289
+ // Support templates which have initial or final text nodes, or consist only of text
290
+ // Also support HTML entities within the HTML markup.
291
+ ret.replace( /^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, function( all, before, middle, after) {
292
+ frag = jQuery( middle ).get();
293
+
294
+ storeTmplItems( frag );
295
+ if ( before ) {
296
+ frag = unencode( before ).concat(frag);
297
+ }
298
+ if ( after ) {
299
+ frag = frag.concat(unencode( after ));
300
+ }
301
+ });
302
+ return frag ? frag : unencode( ret );
303
+ }
304
+
305
+ function unencode( text ) {
306
+ // Use createElement, since createTextNode will not render HTML entities correctly
307
+ var el = document.createElement( "div" );
308
+ el.innerHTML = text;
309
+ return jQuery.makeArray(el.childNodes);
310
+ }
311
+
312
+ // Generate a reusable function that will serve to render a template against data
313
+ function buildTmplFn( markup ) {
314
+ return new Function("jQuery","$item",
315
+ "var $=jQuery,call,_=[],$data=$item.data;" +
316
+
317
+ // Introduce the data as local variables using with(){}
318
+ "with($data){_.push('" +
319
+
320
+ // Convert the template into pure JavaScript
321
+ jQuery.trim(markup)
322
+ .replace( /([\\'])/g, "\\$1" )
323
+ .replace( /[\r\t\n]/g, " " )
324
+ .replace( /\$\{([^\}]*)\}/g, "{{= $1}}" )
325
+ .replace( /\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,
326
+ function( all, slash, type, fnargs, target, parens, args ) {
327
+ var tag = jQuery.tmpl.tag[ type ], def, expr, exprAutoFnDetect;
328
+ if ( !tag ) {
329
+ throw "Template command not found: " + type;
330
+ }
331
+ def = tag._default || [];
332
+ if ( parens && !/\w$/.test(target)) {
333
+ target += parens;
334
+ parens = "";
335
+ }
336
+ if ( target ) {
337
+ target = unescape( target );
338
+ args = args ? ("," + unescape( args ) + ")") : (parens ? ")" : "");
339
+ // Support for target being things like a.toLowerCase();
340
+ // In that case don't call with template item as 'this' pointer. Just evaluate...
341
+ expr = parens ? (target.indexOf(".") > -1 ? target + parens : ("(" + target + ").call($item" + args)) : target;
342
+ exprAutoFnDetect = parens ? expr : "(typeof(" + target + ")==='function'?(" + target + ").call($item):(" + target + "))";
343
+ } else {
344
+ exprAutoFnDetect = expr = def.$1 || "null";
345
+ }
346
+ fnargs = unescape( fnargs );
347
+ return "');" +
348
+ tag[ slash ? "close" : "open" ]
349
+ .split( "$notnull_1" ).join( target ? "typeof(" + target + ")!=='undefined' && (" + target + ")!=null" : "true" )
350
+ .split( "$1a" ).join( exprAutoFnDetect )
351
+ .split( "$1" ).join( expr )
352
+ .split( "$2" ).join( fnargs ?
353
+ fnargs.replace( /\s*([^\(]+)\s*(\((.*?)\))?/g, function( all, name, parens, params ) {
354
+ params = params ? ("," + params + ")") : (parens ? ")" : "");
355
+ return params ? ("(" + name + ").call($item" + params) : all;
356
+ })
357
+ : (def.$2||"")
358
+ ) +
359
+ "_.push('";
360
+ }) +
361
+ "');}return _;"
362
+ );
363
+ }
364
+ function updateWrapped( options, wrapped ) {
365
+ // Build the wrapped content.
366
+ options._wrap = build( options, true,
367
+ // Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
368
+ jQuery.isArray( wrapped ) ? wrapped : [htmlExpr.test( wrapped ) ? wrapped : jQuery( wrapped ).html()]
369
+ ).join("");
370
+ }
371
+
372
+ function unescape( args ) {
373
+ return args ? args.replace( /\\'/g, "'").replace(/\\\\/g, "\\" ) : null;
374
+ }
375
+ function outerHtml( elem ) {
376
+ var div = document.createElement("div");
377
+ div.appendChild( elem.cloneNode(true) );
378
+ return div.innerHTML;
379
+ }
380
+
381
+ // Store template items in jQuery.data(), ensuring a unique tmplItem data data structure for each rendered template instance.
382
+ function storeTmplItems( content ) {
383
+ var keySuffix = "_" + cloneIndex, elem, elems, newClonedItems = {}, i, l, m;
384
+ for ( i = 0, l = content.length; i < l; i++ ) {
385
+ if ( (elem = content[i]).nodeType !== 1 ) {
386
+ continue;
387
+ }
388
+ elems = elem.getElementsByTagName("*");
389
+ for ( m = elems.length - 1; m >= 0; m-- ) {
390
+ processItemKey( elems[m] );
391
+ }
392
+ processItemKey( elem );
393
+ }
394
+ function processItemKey( el ) {
395
+ var pntKey, pntNode = el, pntItem, tmplItem, key;
396
+ // Ensure that each rendered template inserted into the DOM has its own template item,
397
+ if ( (key = el.getAttribute( tmplItmAtt ))) {
398
+ while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
399
+ if ( pntKey !== key ) {
400
+ // The next ancestor with a _tmplitem expando is on a different key than this one.
401
+ // So this is a top-level element within this template item
402
+ // Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment.
403
+ pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0;
404
+ if ( !(tmplItem = newTmplItems[key]) ) {
405
+ // The item is for wrapped content, and was copied from the temporary parent wrappedItem.
406
+ tmplItem = wrappedItems[key];
407
+ tmplItem = newTmplItem( tmplItem, newTmplItems[pntNode]||wrappedItems[pntNode], null, true );
408
+ tmplItem.key = ++itemKey;
409
+ newTmplItems[itemKey] = tmplItem;
410
+ }
411
+ if ( cloneIndex ) {
412
+ cloneTmplItem( key );
413
+ }
414
+ }
415
+ el.removeAttribute( tmplItmAtt );
416
+ } else if ( cloneIndex && (tmplItem = jQuery.data( el, "tmplItem" )) ) {
417
+ // This was a rendered element, cloned during append or appendTo etc.
418
+ // TmplItem stored in jQuery data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem.
419
+ cloneTmplItem( tmplItem.key );
420
+ newTmplItems[tmplItem.key] = tmplItem;
421
+ pntNode = jQuery.data( el.parentNode, "tmplItem" );
422
+ pntNode = pntNode ? pntNode.key : 0;
423
+ }
424
+ if ( tmplItem ) {
425
+ pntItem = tmplItem;
426
+ // Find the template item of the parent element.
427
+ // (Using !=, not !==, since pntItem.key is number, and pntNode may be a string)
428
+ while ( pntItem && pntItem.key != pntNode ) {
429
+ // Add this element as a top-level node for this rendered template item, as well as for any
430
+ // ancestor items between this item and the item of its parent element
431
+ pntItem.nodes.push( el );
432
+ pntItem = pntItem.parent;
433
+ }
434
+ // Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering...
435
+ delete tmplItem._ctnt;
436
+ delete tmplItem._wrap;
437
+ // Store template item as jQuery data on the element
438
+ jQuery.data( el, "tmplItem", tmplItem );
439
+ }
440
+ function cloneTmplItem( key ) {
441
+ key = key + keySuffix;
442
+ tmplItem = newClonedItems[key] =
443
+ (newClonedItems[key] || newTmplItem( tmplItem, newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent, null, true ));
444
+ }
445
+ }
446
+ }
447
+
448
+ //---- Helper functions for template item ----
449
+
450
+ function tiCalls( content, tmpl, data, options ) {
451
+ if ( !content ) {
452
+ return stack.pop();
453
+ }
454
+ stack.push({ _: content, tmpl: tmpl, item:this, data: data, options: options });
455
+ }
456
+
457
+ function tiNest( tmpl, data, options ) {
458
+ // nested template, using {{tmpl}} tag
459
+ return jQuery.tmpl( jQuery.template( tmpl ), data, options, this );
460
+ }
461
+
462
+ function tiWrap( call, wrapped ) {
463
+ // nested template, using {{wrap}} tag
464
+ var options = call.options || {};
465
+ options.wrapped = wrapped;
466
+ // Apply the template, which may incorporate wrapped content,
467
+ return jQuery.tmpl( jQuery.template( call.tmpl ), call.data, options, call.item );
468
+ }
469
+
470
+ function tiHtml( filter, textOnly ) {
471
+ var wrapped = this._wrap;
472
+ return jQuery.map(
473
+ jQuery( jQuery.isArray( wrapped ) ? wrapped.join("") : wrapped ).filter( filter || "*" ),
474
+ function(e) {
475
+ return textOnly ?
476
+ e.innerText || e.textContent :
477
+ e.outerHTML || outerHtml(e);
478
+ });
479
+ }
480
+
481
+ function tiUpdate() {
482
+ var coll = this.nodes;
483
+ jQuery.tmpl( null, null, null, this).insertBefore( coll[0] );
484
+ jQuery( coll ).remove();
485
+ }
486
+ })( jQuery );