wontomedia 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/COPYING +661 -0
  2. data/COPYING.DOCUMENTATION +450 -0
  3. data/LICENSE +661 -0
  4. data/README.markdown +56 -0
  5. data/Rakefile +185 -0
  6. data/VERSION.yml +4 -0
  7. data/app/controllers/admin_controller.rb +144 -0
  8. data/app/controllers/application_controller.rb +29 -0
  9. data/app/controllers/connections_controller.rb +150 -0
  10. data/app/controllers/items_controller.rb +365 -0
  11. data/app/helpers/connections_helper.rb +67 -0
  12. data/app/helpers/format_helper.rb +154 -0
  13. data/app/helpers/items_helper.rb +105 -0
  14. data/app/models/category_item.rb +23 -0
  15. data/app/models/connection.rb +210 -0
  16. data/app/models/individual_item.rb +23 -0
  17. data/app/models/item.rb +86 -0
  18. data/app/models/property_item.rb +23 -0
  19. data/app/models/qualified_item.rb +23 -0
  20. data/app/views/admin/index.html.erb +74 -0
  21. data/app/views/connections/_index_outbound_links.html.erb +48 -0
  22. data/app/views/connections/_spo_select_controls.html.erb +151 -0
  23. data/app/views/connections/edit.html.erb +70 -0
  24. data/app/views/connections/index.html.erb +84 -0
  25. data/app/views/connections/new.html.erb +61 -0
  26. data/app/views/connections/show.html.erb +110 -0
  27. data/app/views/items/_active_content.html.erb +26 -0
  28. data/app/views/items/_content_examples.html.erb +55 -0
  29. data/app/views/items/_core_tasks.html.erb +23 -0
  30. data/app/views/items/_form_fields.html.erb +69 -0
  31. data/app/views/items/_list_outbound_links.html.erb +58 -0
  32. data/app/views/items/_screen_select.html.erb +24 -0
  33. data/app/views/items/_show_outbound_links.html.erb +70 -0
  34. data/app/views/items/_topic_list.html.erb +26 -0
  35. data/app/views/items/_type_select.html.erb +47 -0
  36. data/app/views/items/edit.html.erb +63 -0
  37. data/app/views/items/index.html.erb +74 -0
  38. data/app/views/items/new.html.erb +124 -0
  39. data/app/views/items/newpop.html.erb +58 -0
  40. data/app/views/items/show.html.erb +209 -0
  41. data/app/views/layouts/_amazon_ads.html.erb +55 -0
  42. data/app/views/layouts/_glossary_help_box.html.erb +43 -0
  43. data/app/views/layouts/_google_ads.html.erb +40 -0
  44. data/app/views/layouts/_language_select.html.erb +24 -0
  45. data/app/views/layouts/_login_controls.html.erb +24 -0
  46. data/app/views/layouts/_master_help.html.erb +24 -0
  47. data/app/views/layouts/_navigation_menu.html.erb +39 -0
  48. data/app/views/layouts/_search_box.html.erb +27 -0
  49. data/app/views/layouts/_status_msgs.html.erb +25 -0
  50. data/app/views/layouts/application.html.erb +67 -0
  51. data/app/views/layouts/base.html.erb +93 -0
  52. data/app/views/layouts/home.html.erb +67 -0
  53. data/app/views/layouts/popup.html.erb +23 -0
  54. data/assets/wontomedia-sample.rb +47 -0
  55. data/config/asset_packages.yml +44 -0
  56. data/config/boot.rb +110 -0
  57. data/config/cucumber.yml +65 -0
  58. data/config/database-mysql-development.yml +47 -0
  59. data/config/database-mysql.yml +26 -0
  60. data/config/environment.rb +94 -0
  61. data/config/environments/cucumber.rb +29 -0
  62. data/config/environments/development.rb +26 -0
  63. data/config/environments/production.rb +33 -0
  64. data/config/environments/test.rb +31 -0
  65. data/config/initializers/inflections.rb +19 -0
  66. data/config/initializers/mime_types.rb +14 -0
  67. data/config/initializers/new_rails_defaults.rb +26 -0
  68. data/config/locales/en.yml +14 -0
  69. data/config/routes.rb +37 -0
  70. data/db/fixtures/connections.yml +96 -0
  71. data/db/fixtures/items.yml +277 -0
  72. data/db/migrate/20090312212805_create_items.rb +31 -0
  73. data/db/migrate/20090406221320_create_connections.rb +32 -0
  74. data/db/migrate/20090411014503_add_type_for_item_subclasses.rb +29 -0
  75. data/db/migrate/20090415142152_rename_item_type.rb +31 -0
  76. data/db/migrate/20090518022918_rename_object_and_self.rb +33 -0
  77. data/db/migrate/20090529171442_add_flags_to_items.rb +27 -0
  78. data/db/migrate/20090529171508_add_flags_to_connections.rb +27 -0
  79. data/db/migrate/20090605213800_flags_columns_not_null.rb +29 -0
  80. data/db/migrate/20090605215028_flags_columns_default_zero.rb +29 -0
  81. data/db/schema.rb +30 -0
  82. data/default-custom/app/views/items/_home_extern_list.html.erb +32 -0
  83. data/default-custom/app/views/items/_home_introductory_text.html.erb +70 -0
  84. data/default-custom/app/views/items/home.html.erb +77 -0
  85. data/default-custom/public/images/logo.png +0 -0
  86. data/default-custom/public/images/logo.svg +74 -0
  87. data/default-custom/public/stylesheets/wm.css +301 -0
  88. data/doc/README.markdown +44 -0
  89. data/doc/README_FOR_APP +82 -0
  90. data/doc/customization.markdown +93 -0
  91. data/doc/scripts/rake-customize.markdown +83 -0
  92. data/lib/helpers/connection_helper.rb +41 -0
  93. data/lib/helpers/item_helper.rb +141 -0
  94. data/lib/helpers/tripple_navigation.rb +158 -0
  95. data/lib/tasks/cucumber.rake +83 -0
  96. data/lib/tasks/customize.rake +70 -0
  97. data/lib/tasks/db.rake +65 -0
  98. data/lib/tasks/javascript_testing_tasks.rake +176 -0
  99. data/public/404.html +50 -0
  100. data/public/422.html +50 -0
  101. data/public/500.html +53 -0
  102. data/public/dispatch.cgi +20 -0
  103. data/public/dispatch.fcgi +34 -0
  104. data/public/dispatch.rb +20 -0
  105. data/public/favicon.ico +0 -0
  106. data/public/images/blank_error_icon.png +0 -0
  107. data/public/images/blank_status_icon.png +0 -0
  108. data/public/images/error_error_icon.png +0 -0
  109. data/public/images/error_status_icon.png +0 -0
  110. data/public/images/good_status_icon.png +0 -0
  111. data/public/images/help_icon.png +0 -0
  112. data/public/images/twitter_icon.png +0 -0
  113. data/public/images/warn_error_icon.png +0 -0
  114. data/public/images/working_status_icon.gif +0 -0
  115. data/public/javascripts/application.js +56 -0
  116. data/public/javascripts/controls.js +963 -0
  117. data/public/javascripts/dragdrop.js +973 -0
  118. data/public/javascripts/effects.js +1128 -0
  119. data/public/javascripts/event.simulate.js +64 -0
  120. data/public/javascripts/fancybox.js +43 -0
  121. data/public/javascripts/forConnectionsForms.js +218 -0
  122. data/public/javascripts/forItemsForms.js +511 -0
  123. data/public/javascripts/itemCreatePopup.js +115 -0
  124. data/public/javascripts/itemTitleToName.js +119 -0
  125. data/public/javascripts/jquery.js +4376 -0
  126. data/public/javascripts/modalbox.js +502 -0
  127. data/public/javascripts/prototype.js +4320 -0
  128. data/public/javascripts/reconcileJQueryAndPrototype.js +19 -0
  129. data/public/robots.txt +7 -0
  130. data/public/stylesheets/blank.gif +0 -0
  131. data/public/stylesheets/fancy_close.png +0 -0
  132. data/public/stylesheets/fancy_loading.png +0 -0
  133. data/public/stylesheets/fancy_nav_left.png +0 -0
  134. data/public/stylesheets/fancy_nav_right.png +0 -0
  135. data/public/stylesheets/fancy_shadow_e.png +0 -0
  136. data/public/stylesheets/fancy_shadow_n.png +0 -0
  137. data/public/stylesheets/fancy_shadow_ne.png +0 -0
  138. data/public/stylesheets/fancy_shadow_nw.png +0 -0
  139. data/public/stylesheets/fancy_shadow_s.png +0 -0
  140. data/public/stylesheets/fancy_shadow_se.png +0 -0
  141. data/public/stylesheets/fancy_shadow_sw.png +0 -0
  142. data/public/stylesheets/fancy_shadow_w.png +0 -0
  143. data/public/stylesheets/fancy_title_left.png +0 -0
  144. data/public/stylesheets/fancy_title_main.png +0 -0
  145. data/public/stylesheets/fancy_title_over.png +0 -0
  146. data/public/stylesheets/fancy_title_right.png +0 -0
  147. data/public/stylesheets/fancybox.css +333 -0
  148. data/public/stylesheets/modalbox.css +110 -0
  149. data/public/stylesheets/scaffold.css +36 -0
  150. data/public/stylesheets/spinner.gif +0 -0
  151. data/script/about +4 -0
  152. data/script/console +3 -0
  153. data/script/cucumber +10 -0
  154. data/script/dbconsole +3 -0
  155. data/script/destroy +3 -0
  156. data/script/generate +3 -0
  157. data/script/performance/benchmarker +3 -0
  158. data/script/performance/profiler +3 -0
  159. data/script/performance/request +3 -0
  160. data/script/plugin +3 -0
  161. data/script/process/inspector +3 -0
  162. data/script/process/reaper +3 -0
  163. data/script/process/spawner +3 -0
  164. data/script/runner +3 -0
  165. data/script/server +3 -0
  166. data/vendor/plugins/asset_packager/CHANGELOG +122 -0
  167. data/vendor/plugins/asset_packager/README +178 -0
  168. data/vendor/plugins/asset_packager/Rakefile +22 -0
  169. data/vendor/plugins/asset_packager/about.yml +8 -0
  170. data/vendor/plugins/asset_packager/init.rb +2 -0
  171. data/vendor/plugins/asset_packager/install.rb +1 -0
  172. data/vendor/plugins/asset_packager/lib/jsmin.rb +205 -0
  173. data/vendor/plugins/asset_packager/lib/synthesis/asset_package.rb +212 -0
  174. data/vendor/plugins/asset_packager/lib/synthesis/asset_package_helper.rb +39 -0
  175. data/vendor/plugins/asset_packager/tasks/asset_packager_tasks.rake +23 -0
  176. data/vendor/plugins/asset_packager/test/asset_package_helper_development_test.rb +100 -0
  177. data/vendor/plugins/asset_packager/test/asset_package_helper_production_test.rb +140 -0
  178. data/vendor/plugins/asset_packager/test/asset_packager_test.rb +92 -0
  179. data/vendor/plugins/asset_packager/test/asset_packages.yml +20 -0
  180. data/vendor/plugins/asset_packager/test/assets/javascripts/application.js +2 -0
  181. data/vendor/plugins/asset_packager/test/assets/javascripts/bar.js +4 -0
  182. data/vendor/plugins/asset_packager/test/assets/javascripts/controls.js +815 -0
  183. data/vendor/plugins/asset_packager/test/assets/javascripts/dragdrop.js +913 -0
  184. data/vendor/plugins/asset_packager/test/assets/javascripts/effects.js +958 -0
  185. data/vendor/plugins/asset_packager/test/assets/javascripts/foo.js +4 -0
  186. data/vendor/plugins/asset_packager/test/assets/javascripts/prototype.js +2006 -0
  187. data/vendor/plugins/asset_packager/test/assets/stylesheets/bar.css +16 -0
  188. data/vendor/plugins/asset_packager/test/assets/stylesheets/foo.css +16 -0
  189. data/vendor/plugins/asset_packager/test/assets/stylesheets/header.css +16 -0
  190. data/vendor/plugins/asset_packager/test/assets/stylesheets/screen.css +16 -0
  191. data/vendor/plugins/asset_packager/test/assets/stylesheets/subdir/bar.css +16 -0
  192. data/vendor/plugins/asset_packager/test/assets/stylesheets/subdir/foo.css +16 -0
  193. metadata +265 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Event.simulate(@element, eventName[, options]) -> Element
3
+ *
4
+ * - @element: element to fire event on
5
+ * - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported)
6
+ * - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc.
7
+ *
8
+ * $('foo').simulate('click'); // => fires "click" event on an element with id=foo
9
+ *
10
+ **/
11
+ (function(){
12
+
13
+ var eventMatchers = {
14
+ 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
15
+ 'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
16
+ }
17
+ var defaultOptions = {
18
+ pointerX: 0,
19
+ pointerY: 0,
20
+ button: 0,
21
+ ctrlKey: false,
22
+ altKey: false,
23
+ shiftKey: false,
24
+ metaKey: false,
25
+ bubbles: true,
26
+ cancelable: true
27
+ }
28
+
29
+ Event.simulate = function(element, eventName) {
30
+ var options = Object.extend(Object.clone(defaultOptions), arguments[2] || { });
31
+ var oEvent, eventType = null;
32
+
33
+ element = $(element);
34
+
35
+ for (var name in eventMatchers) {
36
+ if (eventMatchers[name].test(eventName)) { eventType = name; break; }
37
+ }
38
+
39
+ if (!eventType)
40
+ throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
41
+
42
+ if (document.createEvent) {
43
+ oEvent = document.createEvent(eventType);
44
+ if (eventType == 'HTMLEvents') {
45
+ oEvent.initEvent(eventName, options.bubbles, options.cancelable);
46
+ }
47
+ else {
48
+ oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
49
+ options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
50
+ options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
51
+ }
52
+ element.dispatchEvent(oEvent);
53
+ }
54
+ else {
55
+ options.clientX = options.pointerX;
56
+ options.clientY = options.pointerY;
57
+ oEvent = Object.extend(document.createEventObject(), options);
58
+ element.fireEvent('on' + eventName, oEvent);
59
+ }
60
+ return element;
61
+ }
62
+
63
+ Element.addMethods({ simulate: Event.simulate });
64
+ })()
@@ -0,0 +1,43 @@
1
+ /*
2
+ * FancyBox - jQuery Plugin
3
+ * Simple and fancy lightbox alternative
4
+ *
5
+ * Copyright (c) 20010 Janis Skarnelis
6
+ * Examples and documentation at: http://fancybox.net
7
+ *
8
+ * Version: 1.3.0 (02/02/2010)
9
+ * Requires: jQuery v1.3+
10
+ *
11
+ * Dual licensed under the MIT and GPL licenses:
12
+ * http://www.opensource.org/licenses/mit-license.php
13
+ * http://www.gnu.org/licenses/gpl.html
14
+ */
15
+
16
+ ;(function(b){function H(){v.hide();r.onerror=r.onload=null;F&&F.abort();l.empty()}function Q(){b.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>',{scrolling:"no",padding:20,transitionIn:"none",transitionOut:"none"})}function B(){H();var a=q[s];e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));var d,f,o=a.title||b(a).title||e.title||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?
17
+ b(a).children("img:first"):b(a);if(o==""&&e.orig)o=e.orig.attr("alt");d=a.nodeName&&/^(?:javascript|#)/i.test(a.href)?e.href||null:e.href||a.href||null;if(e.type){f=e.type;if(!d)d=e.content}else if(e.content)f="html";else if(d)if(d.match(I))f="image";else if(d.match(T))f="swf";else if(b(a).hasClass("iframe"))f="iframe";else if(d.match(/#/)){a=d.substr(d.indexOf("#"));f=b(a).length>0?"inline":"ajax"}else f="ajax";else f="inline";e.type=f;e.href=d;e.title=o;if(e.autoDimensions&&e.type!=="iframe"&&e.type!==
18
+ "swf"){e.width="auto";e.height="auto"}if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=false;e.enableEscapeButton=false;e.showCloseButton=false}if(b.isFunction(e.onStart))if(e.onStart(q,s,e)===false){h=false;return}l.css("padding",t+e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(i.children())});switch(f){case "html":l.html(e.content);G();break;case "inline":b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",
19
+ function(){b(this).replaceWith(i.children())}).bind("fancybox-cancel",function(){b(this).replaceWith(l.children())});b(a).appendTo(l);G();break;case "image":h=false;b.fancybox.showActivity();r=new Image;r.onerror=function(){Q()};r.onload=function(){r.onerror=null;r.onload=null;U()};r.src=d;break;case "swf":var u="",w="";u+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+d+'"></param>';b.each(e.swf,function(p,R){u+=
20
+ '<param name="'+p+'" value="'+R+'"></param>';w+=" "+p+'="'+R+'"'});u+='<embed src="'+d+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+w+"></embed></object>";l.html(u);G();break;case "ajax":a=d.split("#",2);f=e.ajax.data||{};if(a.length>1){d=a[0];typeof f=="string"?(f+="&selector="+a[1]):(f.selector=a[1])}h=false;b.fancybox.showActivity();F=b.ajax(b.extend(e.ajax,{url:d,data:f,error:Q,success:function(p){if(F.status==200){l.html(p);G()}}}));break;case "iframe":b('<iframe id="fancybox-frame" name="fancybox-frame'+
21
+ (new Date).getTime()+'" frameborder="0" hspace="0" scrolling="'+e.scrolling+'" src="'+e.href+'"></iframe>').appendTo(l);J();break}}function U(){h=true;e.width=r.width;e.height=r.height;b("<img />").attr({id:"fancybox-img",src:r.src,alt:e.title}).appendTo(l);J()}function G(){l.width(e.width);l.height(e.height);if(e.width=="auto")e.width=l.width();if(e.height=="auto")e.height=l.height();J()}function J(){v.hide();if(g.is(":visible")&&b.isFunction(c.onCleanup))if(c.onCleanup(j,n,c)===false){b.event.trigger("fancybox-cancel");
22
+ h=false;return}j=q;n=s;c=e;i.get(0).scrollTop=0;i.get(0).scrollLeft=0;if(c.overlayShow){K&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});y.css({"background-color":c.overlayColor,opacity:c.overlayOpacity}).unbind().show()}m=V();W();if(g.is(":visible")){b(z.add(C).add(D)).hide();var a=g.position();k={top:a.top,left:a.left,width:g.width(),height:g.height()};
23
+ var d=k.width==m.width&&k.height==m.height;i.fadeOut(c.changeFade,function(){function f(){i.html(l.contents()).fadeIn(c.changeFade,L)}b.event.trigger("fancybox-change");i.css({top:c.padding,left:c.padding,width:Math.max(k.width-c.padding*2,1),height:Math.max(k.height-c.padding*2,1)}).empty().css("overflow","hidden");A.prop=0;b(A).animate({prop:1},{duration:d?0:c.changeSpeed,easing:c.easingChange,step:M,complete:f})})}else{g.css("opacity",1);if(c.transitionIn=="elastic"){k=S();i.css({top:c.padding,
24
+ left:c.padding,width:Math.max(k.width-c.padding*2,1),height:Math.max(k.height-c.padding*2,1)}).html(l.contents());g.css(k).show();if(c.opacity)m.opacity=0;A.prop=0;b(A).animate({prop:1},{duration:c.speedIn,easing:c.easingIn,step:M,complete:L})}else{i.css({top:c.padding,left:c.padding,width:Math.max(m.width-c.padding*2,1),height:Math.max(m.height-c.padding*2-x,1)}).html(l.contents());g.css(m).fadeIn(c.transitionIn=="none"?0:c.speedIn,L)}}}function M(a){var d=Math.round(k.width+(m.width-k.width)*a),
25
+ f=Math.round(k.height+(m.height-k.height)*a),o=Math.round(k.top+(m.top-k.top)*a),u=Math.round(k.left+(m.left-k.left)*a);g.css({width:d+"px",height:f+"px",top:o+"px",left:u+"px"});d=Math.max(d-c.padding*2,0);f=Math.max(f-(c.padding*2+x*a),0);i.css({width:d+"px",height:f+"px"});if(typeof m.opacity!=="undefined")g.css("opacity",a<0.5?0.5:a)}function L(){i.css("overflow",overflow=c.scrolling=="auto"?c.type=="image"||c.type=="iframe"||c.type=="swf"?"hidden":"auto":c.scrolling=="yes"?"auto":"visible");
26
+ if(!b.support.opacity){i.get(0).style.removeAttribute("filter");g.get(0).style.removeAttribute("filter")}b("#fancybox-title").show();c.hideOnContentClick&&i.one("click",b.fancybox.close);c.hideOnOverlayClick&&y.one("click",b.fancybox.close);c.showCloseButton&&z.show();X();b(window).bind("resize.fb",b.fancybox.center);c.centerOnScroll?b(window).bind("scroll.fb",b.fancybox.center):b(window).unbind("scroll.fb");b.isFunction(c.onComplete)&&c.onComplete(j,n,c);h=false;Y()}function V(){var a=N(),d={},f=
27
+ c.margin,o=c.autoScale,u=(t+f)*2,w=(t+f)*2,p=c.padding*2;if(c.width.toString().indexOf("%")>-1){d.width=a[0]*parseFloat(c.width)/100-t*2;o=false}else d.width=c.width+p;if(c.height.toString().indexOf("%")>-1){d.height=a[1]*parseFloat(c.height)/100-t*2;o=false}else d.height=c.height+p;if(o&&(d.width>a[0]-u||d.height>a[1]-w))if(e.type=="image"||e.type=="swf"){u+=p;w+=p;o=Math.min(Math.min(a[0]-u,c.width)/c.width,Math.min(a[1]-w,c.height)/c.height);d.width=Math.round(o*(d.width-p))+p;d.height=Math.round(o*
28
+ (d.height-p))+p}else{d.width=Math.min(d.width,a[0]-u);d.height=Math.min(d.height,a[1]-w)}d.top=a[3]+(a[1]-(d.height+t*2))*0.5;d.left=a[2]+(a[0]-(d.width+t*2))*0.5;if(c.autoScale==false){d.top=Math.max(a[3]+f,d.top);d.left=Math.max(a[2]+f,d.left)}return d}function S(){var a=e.orig?b(e.orig):false,d={};if(a&&a.length){a=Z(a);d={width:a.width+c.padding*2,height:a.height+c.padding*2,top:a.top-c.padding-t,left:a.left-c.padding-t}}else{a=N();d={width:1,height:1,top:a[3]+a[1]*0.5,left:a[2]+a[0]*0.5}}return d}
29
+ function X(){b(document).unbind("keydown.fb").bind("keydown.fb",function(a){if(a.keyCode==27&&c.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if(a.keyCode==37){a.preventDefault();b.fancybox.prev()}else if(a.keyCode==39){a.preventDefault();b.fancybox.next()}});if(b.fn.mousewheel){g.unbind("mousewheel.fb");j.length>1&&g.bind("mousewheel.fb",function(a,d){a.preventDefault();h||d==0||(d>0?b.fancybox.prev():b.fancybox.next())})}if(c.showNavArrows){if(c.cyclic&&j.length>1||n!=0)C.show();
30
+ if(c.cyclic&&j.length>1||n!=j.length-1)D.show()}}function Y(){if(j.length-1>n){var a=j[n+1].href;if(typeof a!=="undefined"&&a.match(I)){var d=new Image;d.src=a}}if(n>0){a=j[n-1].href;if(typeof a!=="undefined"&&a.match(I)){d=new Image;d.src=a}}}function $(){if(v.is(":visible")){b("div",v).css("top",O*-40+"px");O=(O+1)%12}else clearInterval(P)}function N(){return[b(window).width(),b(window).height(),b(document).scrollLeft(),b(document).scrollTop()]}function Z(a){var d=a.offset();d.top+=parseFloat(a.css("paddingTop"))||
31
+ 0;d.left+=parseFloat(a.css("paddingLeft"))||0;d.top+=parseFloat(a.css("border-top-width"))||0;d.left+=parseFloat(a.css("border-left-width"))||0;d.width=a.width();d.height=a.height();return d}function W(){b("#fancybox-title").remove();x=0;if(c.titleShow!=false){var a=c.title;a=b.isFunction(c.titleFormat)?c.titleFormat(a,j,n,c):aa(a);if(!(!a||a=="")){var d=m.width-c.padding*2;b('<div id="fancybox-title" class="'+("fancybox-title-"+c.titlePosition)+'" />').css({width:d,paddingLeft:c.padding,paddingRight:c.padding}).html(a).appendTo("body");
32
+ switch(c.titlePosition){case "inside":x=b("#fancybox-title").outerHeight(true)-c.padding;m.height+=x;break;case "over":b("#fancybox-title").css("bottom",c.padding);break;default:b("#fancybox-title").css("bottom",b("#fancybox-title").outerHeight(true)*-1);break}b("#fancybox-title").appendTo(E).hide();K&&b("#fancybox-title span").fixPNG()}}}function aa(a){if(a&&a.length)switch(c.titlePosition){case "inside":return a;case "over":return'<span id="fancybox-title-over">'+a+"</span>";default:return'<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">'+
33
+ a+'</span><span id="fancybox-title-right"></span></span>'}return false}function ba(){if(!b("#fancybox-wrap").length){b("body").append(l=b('<div id="fancybox-tmp"></div>'),v=b('<div id="fancybox-loading"><div></div></div>'),y=b('<div id="fancybox-overlay"></div>'),g=b('<div id="fancybox-wrap"></div>'));E=b('<div id="fancybox-outer"></div>').append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>').appendTo(g);
34
+ E.append(i=b('<div id="fancybox-inner"></div>'),z=b('<a id="fancybox-close"></a>'),C=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),D=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));z.click(b.fancybox.close);v.click(b.fancybox.cancel);C.click(function(a){a.preventDefault();b.fancybox.prev()});D.click(function(a){a.preventDefault();b.fancybox.next()});b.support.opacity||E.find(".fancy-bg").fixPNG();
35
+ if(K){b(z.add(".fancy-ico").add("div",v)).fixPNG();y.get(0).style.setExpression("height","document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");v.get(0).style.setExpression("top","(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");E.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>')}}}
36
+ var l,v,y,g,E,i,z,C,D,s=0,e={},q=[],n=0,c={},j=[],F=null,r=new Image,I=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,T=/[^\.]\.(swf)\s*$/i,P,O=1,k,m,h=false,t=20,A=b.extend(b("<div/>")[0],{prop:0}),x=0,K=!b.support.opacity&&!window.XMLHttpRequest;b.fn.fixPNG=function(){return this.each(function(){var a=b(this).css("backgroundImage");if(a.match(/^url\(["']?(.*\.png)["']?\)$/i)){a=RegExp.$1;b(this).css({backgroundImage:"none",filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod="+
37
+ (b(this).css("backgroundRepeat")=="no-repeat"?"crop":"scale")+", src='"+a+"')"}).each(function(){var d=b(this).css("position");d!="absolute"&&d!="relative"&&b(this).css("position","relative")}).css("zoom",1)}})};b.fn.fancybox=function(a){b(this).data("fancybox",b.extend({},a));b(this).unbind("click.fb").bind("click.fb",function(d){d.preventDefault();if(!h){h=true;b(this).blur();q=[];s=0;d=b(this).attr("rel")||"";if(!d||d==""||d==="nofollow")q.push(this);else{q=b("a[rel="+d+"], area[rel="+d+"]");s=
38
+ q.index(this)}B();return false}});return this};b.fancybox=function(a,d){if(!h){h=true;q=[];s=0;if(b.isArray(a)){for(var f=0,o=a.length;f<o;f++)if(typeof a[f]=="object")b(a[f]).data("fancybox",b.extend({},d,a[f]));else a[f]=b({}).data("fancybox",b.extend({content:a[f]},d));q=jQuery.merge(q,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},d,a));else a=b({}).data("fancybox",b.extend({content:a},d));q.push(a)}B()}};b.fancybox.showActivity=function(){clearInterval(P);v.show();P=setInterval($,
39
+ 66)};b.fancybox.hideActivity=function(){v.hide()};b.fancybox.next=function(){return b.fancybox.pos(n+1)};b.fancybox.prev=function(){return b.fancybox.pos(n-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);if(a>-1&&j.length>a){s=a;B()}if(c.cyclic&&j.length>1&&a<0){s=j.length-1;B()}if(c.cyclic&&j.length>1&&a>=j.length){s=0;B()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");H();e&&b.isFunction(e.onCancel)&&e.onCancel(q,s,e);h=false}};b.fancybox.close=function(){function a(){y.fadeOut("fast");
40
+ g.hide();b.event.trigger("fancybox-cleanup");i.empty();b.isFunction(c.onClosed)&&c.onClosed(j,n,c);j=e=[];n=s=0;c=e={};h=false}if(!(h||g.is(":hidden"))){h=true;if(c&&b.isFunction(c.onCleanup))if(c.onCleanup(j,n,c)===false){h=false;return}H();b(z.add(C).add(D)).hide();b("#fancybox-title").remove();g.add(i).add(y).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");i.css("overflow","hidden");if(c.transitionOut=="elastic"){k=S();var d=g.position();m={top:d.top,left:d.left,
41
+ width:g.width(),height:g.height()};if(c.opacity)m.opacity=1;A.prop=1;b(A).animate({prop:0},{duration:c.speedOut,easing:c.easingOut,step:M,complete:a})}else g.fadeOut(c.transitionOut=="none"?0:c.speedOut,a)}};b.fancybox.resize=function(){if(!(h||g.is(":hidden"))){h=true;var a=i.wrapInner("<div style='overflow:auto'></div>").children(),d=a.height();g.css({height:d+c.padding*2+x});i.css({height:d});a.replaceWith(a.children());b.fancybox.center()}};b.fancybox.center=function(){h=true;var a=N(),d=c.margin,
42
+ f={};f.top=a[3]+(a[1]-(g.height()-x+t*2))*0.5;f.left=a[2]+(a[0]-(g.width()+t*2))*0.5;f.top=Math.max(a[3]+d,f.top);f.left=Math.max(a[2]+d,f.left);g.css(f);h=false};b.fn.fancybox.defaults={padding:10,margin:20,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.3,overlayColor:"#666",titleShow:true,titlePosition:"outside",
43
+ titleFormat:null,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,onStart:null,onCancel:null,onComplete:null,onCleanup:null,onClosed:null};b(document).ready(function(){ba()})})(jQuery);
@@ -0,0 +1,218 @@
1
+ // WontoMedia - a wontology web application
2
+ // Copyright (C) 2010 - Glen E. Ivey
3
+ // www.wontology.com
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License version
7
+ // 3 as published by the Free Software Foundation.
8
+ //
9
+ // This program is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU Affero General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU Affero General Public License
15
+ // along with this program in the file COPYING and/or LICENSE. If not,
16
+ // see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ var selectElems = [ "subject", "predicate", "obj", "submit" ];
20
+ var connectionSubmit;
21
+ var l = window.location;
22
+ var base = l.protocol + "//" + l.hostname + ":" + l.port;
23
+ var lastValue = {}
24
+
25
+
26
+ // define fields subject to check, order they occur in form
27
+ var requiredConnectionElements = [ "subject", "predicate", "obj", "submit" ];
28
+ var connectionElementNames = [ "Subject selector", "Relationship selector",
29
+ "Object selector" ];
30
+
31
+ // encoding: -1 -> haven't checked yet
32
+ // false -> no error
33
+ // true -> error condition present
34
+ var connectionFormErrors = {};
35
+
36
+
37
+ if ((typeof inAConnectionsForm !== 'undefined') && inAConnectionsForm){
38
+ connectionSubmit = $('connection_submit');
39
+
40
+ lastValue = {
41
+ subject : $('connection_subject_id').value,
42
+ predicate : $('connection_predicate_id').value,
43
+ obj : $('connection_obj_id').value
44
+ };
45
+
46
+ for (var c=0; c < requiredConnectionElements.length-1; c++)
47
+ connectionFormErrors[requiredConnectionElements[c]] =
48
+ creatingNewConnection ? -1 : false;
49
+
50
+ for (var c=0; c < selectElems.length; c++){
51
+ createOnchangeHandler(selectElems[c]);
52
+ createOnfocusHandler(selectElems[c]);
53
+ }
54
+
55
+ if (creatingNewConnection)
56
+ // connections/new -- can't submit a blank form
57
+ makeButtonSeemDisabled(connectionSubmit);
58
+ else // connections/##/edit -- can submit as-is form
59
+ makeButtonSeemEnabled(connectionSubmit);
60
+
61
+ connectionSubmit.observe('click', submitOnclickHandler);
62
+ }
63
+
64
+
65
+ function createOnchangeHandler(thisName){
66
+ var thisElem = $('connection_' + thisName + '_id');
67
+ if (thisElem == null)
68
+ thisElem = $('connection_' + thisName);
69
+ thisElem.observe('change',
70
+ function(){ // nest all these fn defs for closure
71
+ if (thisElem.value != lastValue[thisName]){
72
+ var lastLast = lastValue[thisName];
73
+ lastValue[thisName] = thisElem.value;
74
+
75
+ if (thisElem.value == ""){
76
+ divToBlank(thisName);
77
+ flagConnectionAsRequired(thisName);
78
+ }
79
+ else if (thisElem.value == "-1"){
80
+ divToBlank(thisName);
81
+ var type = (thisName == "predicate") ? "verb" : "noun";
82
+ itemCreatePopup(thisElem, type, lastLast);
83
+ }
84
+ else {
85
+ clearError(thisName);
86
+ divToWorking(thisName);
87
+ new Ajax.Request(base + "/items/" + thisElem.value + ".json", {
88
+ method: 'get',
89
+ onSuccess: function(response){
90
+ var itemObject = response.responseJSON;
91
+ var key = getFirstHashKey(itemObject);
92
+ divToText(thisName, itemObject[key]["description"]);
93
+ },
94
+ onFailure: function(){
95
+ divToBlank(thisName);
96
+ }
97
+ });
98
+ }
99
+ refreshSubmitState();
100
+ }
101
+ }
102
+ );
103
+ }
104
+
105
+ function getFirstHashKey(hashObj){
106
+ for (var key in hashObj)
107
+ return key;
108
+ }
109
+
110
+ function divToBlank(name){
111
+ divToImg(name, "blank");
112
+ }
113
+
114
+ function divToWorking(name){
115
+ divToImg(name, "working");
116
+ }
117
+
118
+ function divToImg(divName, imageName){
119
+ $(divName + '_desc').className = "desc";
120
+ $(divName + '_desc').innerHTML =
121
+ "<img alt='' width='32' height='16' id='" + divName + "_status_icon' " +
122
+ " src='/images/" + imageName + "_status_icon.png' />";
123
+ }
124
+
125
+ function divToText(divName, divText){
126
+ if (divText === undefined || divText == null)
127
+ divText = "";
128
+ $(divName + '_desc').className = "";
129
+ $(divName + '_desc').innerHTML = "<p>" + divText.escapeHTML() + "</p>";
130
+ }
131
+
132
+
133
+ function createOnfocusHandler(thisName){
134
+ var thisElem = $('connection_' + thisName + '_id');
135
+ if (thisElem == null)
136
+ thisElem = $('connection_' + thisName);
137
+ thisElem.observe('focus', function(){ onfocusBehavior(thisElem); } );
138
+ }
139
+
140
+ function onfocusBehavior(elem){
141
+ var eId = elem.id;
142
+ var c;
143
+ for (c=0; c < requiredConnectionElements.length; c++){
144
+ var re = new RegExp(requiredConnectionElements[c]);
145
+ var mtch = eId.match(re);
146
+ if (mtch != null && mtch.length > 0)
147
+ break;
148
+ }
149
+
150
+ if (c >= requiredConnectionElements.length)
151
+ return; // Hmmmm..... maybe not
152
+
153
+ var lastToCheck = c-1;
154
+ for (c=0; c <= lastToCheck; c++){
155
+ var ck = $("connection_" + requiredConnectionElements[c] + "_id");
156
+ if (ck.value == null || ck.value == "")
157
+ flagConnectionAsRequired(requiredConnectionElements[c]);
158
+ else
159
+ clearError(requiredConnectionElements[c]);
160
+ }
161
+ refreshSubmitState();
162
+ }
163
+
164
+ function flagConnectionAsRequired(elemName){
165
+ connectionFormErrors[elemName] = true;
166
+ $(elemName + "_required").className = "helpTextFlagged";
167
+ $(elemName + "_error_icon").src = "/images/error_error_icon.png";
168
+ }
169
+
170
+ function clearError(elemName){
171
+ connectionFormErrors[elemName] = false;
172
+ $(elemName + "_required").className = "";
173
+ $(elemName + "_error_icon").src = "/images/blank_error_icon.png";
174
+ }
175
+
176
+ function refreshSubmitState(){
177
+ var detectedAtLeastOneError = false;
178
+ for (var c =0; c < requiredConnectionElements.length-1; c++)
179
+ if (connectionFormErrors[requiredConnectionElements[c]] != false)
180
+ detectedAtLeastOneError = true;
181
+
182
+ if (detectedAtLeastOneError)
183
+ makeButtonSeemDisabled(connectionSubmit);
184
+ else
185
+ makeButtonSeemEnabled(connectionSubmit);
186
+ }
187
+
188
+
189
+ function submitOnclickHandler(ev){
190
+ onfocusBehavior(connectionSubmit);
191
+ var dialogDisplayed = maybeShowErrorDialog();
192
+ if (dialogDisplayed)
193
+ ev.stop();
194
+ }
195
+
196
+ function maybeShowErrorDialog(){
197
+ var newDialogText = "<p>";
198
+
199
+ var accum = false;
200
+ for (var c=0; c < requiredConnectionElements.length-1; c++){
201
+ if (connectionFormErrors[requiredConnectionElements[c]] == true){
202
+ accum = true;
203
+ newDialogText += "The " + connectionElementNames[c] +
204
+ " must have a value. ";
205
+ }
206
+ }
207
+
208
+ if (accum){
209
+ newDialogText += "</p>";
210
+ var titleText =
211
+ creatingNewConnection ? "Can't create this connection yet" :
212
+ "Can't update this connection";
213
+ Modalbox.show(newDialogText, { title: titleText,
214
+ slideDownDuration: 0.25,
215
+ slideUpDuration: 0.1 } );
216
+ }
217
+ return accum;
218
+ }
@@ -0,0 +1,511 @@
1
+ // WontoMedia - a wontology web application
2
+ // Copyright (C) 2010 - Glen E. Ivey
3
+ // www.wontology.com
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License version
7
+ // 3 as published by the Free Software Foundation.
8
+ //
9
+ // This program is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU Affero General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU Affero General Public License
15
+ // along with this program in the file COPYING and/or LICENSE. If not,
16
+ // see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ var nameAjaxStart = 400; // to avoid unnecessary server traffic,
20
+ // wait after Name change before check
21
+
22
+
23
+
24
+
25
+ // package of code to implement required-inputs-can't-be-empty checks
26
+ // (for items/new page)
27
+
28
+
29
+ // define fields subject to check, order they occur in form
30
+ var requiredItemElements = [ "sti_type", "title", "name", "description",
31
+ "submit" ];
32
+ var itemElementNames = [ "Type selector", "Title field", "Name field",
33
+ "Description box", "Create button" ];
34
+ var indexTitle = 1;
35
+ var indexName = 2;
36
+ var indexDescription = 3;
37
+ var maxLengths = [ 0, 255, 80, 65535 ];
38
+
39
+ // globals w/ defaults, real values figured in plumbEvent...()
40
+ var thereIsATypeControl = false;
41
+ var originalItemName = "";
42
+ var controlNamePrefix = "";
43
+ var itemSubmit;
44
+
45
+ // encoding: -1 -> haven't checked yet
46
+ // false -> no error
47
+ // true -> error condition present
48
+ var itemFormErrors = {};
49
+
50
+
51
+ // after key presses, have to wait for browser to update the input field
52
+ // before we check it (delay in ms)
53
+ var dly = 200;
54
+
55
+
56
+ var valueWhenLastChecked = "";
57
+ var uniquenessTimerId = -1;
58
+ var ajaxRequestInProgress = null;
59
+
60
+
61
+ function plumbEventHandlersToItemCreationElements(customizationSelector){
62
+ thereIsATypeControl = ($('item_sti_type') != null);
63
+ for (var c=0; c < requiredItemElements.length-2; c++)
64
+ itemFormErrors["item_" + requiredItemElements[c]] =
65
+ creatingNewItem ? -1 : false;
66
+ for (var c=1; c < requiredItemElements.length-1; c++)
67
+ itemFormErrors["length_" + requiredItemElements[c]] = false;
68
+
69
+ if (!creatingNewItem){
70
+ var arrayOfForms = document.getElementsByTagName('form');
71
+ var newItemId;
72
+ for (var c=0; c < arrayOfForms.length; c++){
73
+ newItemId = arrayOfForms[c].id;
74
+ var mtch = newItemId.match(/item$/);
75
+ if (mtch != null)
76
+ break;
77
+ }
78
+ controlNamePrefix = newItemId.replace(/^edit_/, "").
79
+ replace(/item_?[0-9]*$/, "");
80
+ originalItemName = $(controlNamePrefix + 'item_name').value;
81
+ }
82
+
83
+
84
+ itemSubmit = $(controlNamePrefix + 'item_submit');
85
+ if (thereIsATypeControl){
86
+ var ck = $(controlNamePrefix + 'item_sti_type').value;
87
+ if (ck != null && ck != "")
88
+ itemFormErrors['item_sti_type'] = false;
89
+ }
90
+
91
+
92
+ if (thereIsATypeControl){
93
+ var a = $('item_sti_type');
94
+ a.observe('keyup',
95
+ function(ev){
96
+ if (ev.keyCode != Event.KEY_TAB){ // onfocus does all we need for this
97
+ setTimeout(
98
+ function(){
99
+ checkFieldRequired(a);
100
+ maybeClearIcon('sti_type');
101
+ } ,
102
+ dly
103
+ );
104
+ }
105
+ }
106
+ );
107
+
108
+ a.observe('change',
109
+ function(){
110
+ typeSelectOnchange();
111
+ checkFieldRequired(a);
112
+ maybeClearIcon('sti_type');
113
+ }
114
+ );
115
+ }
116
+
117
+ var b = $(controlNamePrefix + 'item_title');
118
+ var c = $(controlNamePrefix + 'item_name');
119
+ function checkTitle(){
120
+ // this check is unique to Title, do here
121
+ var mtch = b.value.match(/\n|\r/m);
122
+ if (mtch != null && mtch.length > 0){
123
+ $('title_multi_line').className = "helpTextFlagged";
124
+ itemFormErrors['ml_title'] = true;
125
+ $('title_error_icon').src = "/images/error_error_icon.png";
126
+ }
127
+ else {
128
+ $('title_multi_line').className = "";
129
+ itemFormErrors['ml_title'] = false;
130
+ }
131
+
132
+ checkFieldRequired(b);
133
+ checkFieldLength(b, indexTitle);
134
+ maybeClearIcon('title');
135
+ if (creatingNewItem){
136
+ var emptyToNotEmpty = generateFromTitle(b, c);
137
+ if (emptyToNotEmpty){
138
+ itemFormErrors["item_name"] = false;
139
+ $('name_required').className = "";
140
+ maybeClearIcon('name');
141
+ }
142
+ }
143
+ nameFieldValidityCheck();
144
+ }
145
+
146
+ b.observe('change', function(){checkTitle();});
147
+ b.observe('keyup',
148
+ function(ev){
149
+ if (ev.keyCode != Event.KEY_TAB)
150
+ setTimeout(checkTitle, dly);
151
+ }
152
+ );
153
+
154
+ function checkName(){
155
+ nameFieldValidityCheck();
156
+ checkFieldRequired(c);
157
+ checkFieldLength(c, indexName);
158
+ maybeClearIcon('name');
159
+ if (creatingNewItem)
160
+ generateToName(b, c);
161
+
162
+
163
+ // do last, because we're going to skip part of this if other errors...
164
+ maybeCheckNameUniqueness(nameAjaxStart);
165
+ }
166
+ c.observe('change', function(){checkName();});
167
+ c.observe('keyup',
168
+ function(ev){
169
+ if (ev.keyCode != Event.KEY_TAB)
170
+ setTimeout(checkName, dly);
171
+ }
172
+ );
173
+
174
+ function nameFieldValidityCheck(){
175
+ var mtch, val = $(controlNamePrefix + 'item_name').value;
176
+
177
+ $('name_start_char').className = "";
178
+ itemFormErrors['char_1_name'] = false;
179
+ if (val.length > 0){
180
+ mtch = val.match(/^[a-zA-Z]/);
181
+ if (mtch == null || mtch.length == 0){
182
+ $('name_start_char').className = "helpTextFlagged";
183
+ itemFormErrors['char_1_name'] = true;
184
+ $('name_error_icon').src = "/images/error_error_icon.png";
185
+ }
186
+ }
187
+
188
+ $('name_nth_char').className = "";
189
+ itemFormErrors['char_N_name'] = false;
190
+ if (val.length > 1){
191
+ mtch = c.value.match(/^.[a-zA-Z0-9_-]+$/);
192
+ if (mtch == null || mtch.length == 0){
193
+ $('name_nth_char').className = "helpTextFlagged";
194
+ itemFormErrors['char_N_name'] = true;
195
+ $('name_error_icon').src = "/images/error_error_icon.png";
196
+ }
197
+ }
198
+ }
199
+
200
+
201
+ var d = $(controlNamePrefix + 'item_description');
202
+ function checkDescription(){
203
+ checkFieldRequired(d);
204
+ checkFieldLength(d, indexDescription);
205
+ maybeClearIcon('description');
206
+ }
207
+ d.observe('change', function(){checkDescription();});
208
+ d.observe('keyup',
209
+ function(ev){
210
+ if (ev.keyCode != Event.KEY_TAB)
211
+ setTimeout(checkDescription, dly);
212
+ }
213
+ );
214
+
215
+ if (creatingNewItem)
216
+ makeButtonSeemDisabled(itemSubmit);// items/new -- can't submit a blank form
217
+ else
218
+ makeButtonSeemEnabled(itemSubmit); // items/##/edit -- can submit as-is form
219
+
220
+ if (customizationSelector != "submitViaModalbox"){
221
+ itemSubmit.observe('click',
222
+ function(ev){
223
+ if (!okToSubmitItemForm())
224
+ ev.stop();
225
+ }
226
+ );
227
+ }
228
+
229
+ if (thereIsATypeControl)
230
+ a.observe('focus', function(){onfocusCommonBehavior(a);});
231
+ b.observe('focus', function(){onfocusCommonBehavior(b);});
232
+ c.observe('focus', function(){onfocusCommonBehavior(c);});
233
+ d.observe('focus', function(){onfocusCommonBehavior(d);});
234
+ itemSubmit.
235
+ observe('focus', function(){onfocusCommonBehavior(itemSubmit);});
236
+ }
237
+
238
+ function flagItemAsRequired(elemName){
239
+ var req = $(elemName + "_required");
240
+ if ( req != null ){
241
+ req.className = "helpTextFlagged";
242
+ $(elemName + "_error_icon").src = "/images/error_error_icon.png";
243
+ }
244
+ else {
245
+ $(elemName + "_recommended").className = "helpTextFlagged";
246
+ $(elemName + "_error_icon").src = "/images/warn_error_icon.png";
247
+ }
248
+ }
249
+
250
+ function maybeClearIcon(field){
251
+ icon = $(field + "_error_icon");
252
+ var mtch = icon.src.match(/blank_/);
253
+
254
+ // if icon already clear, then don't need to actually clear
255
+ if (mtch == null || mtch.length == 0){
256
+
257
+ // "recommended" is a special case....
258
+ var descReco = itemFormErrors["item_description"];
259
+ itemFormErrors["item_description"] = false;
260
+
261
+ var canClear = true;
262
+ for (var err in itemFormErrors){
263
+ mtch = err.match(new RegExp(field));
264
+ if (mtch != null && mtch.length > 0 && itemFormErrors[err]){
265
+ canClear = false;
266
+ break;
267
+ }
268
+ }
269
+
270
+ itemFormErrors["item_description"] = descReco; // restore
271
+
272
+ if (canClear){
273
+ if (field == "description" && descReco)
274
+ icon.src = "/images/warn_error_icon.png";
275
+ else
276
+ icon.src = "/images/blank_error_icon.png";
277
+ }
278
+ }
279
+
280
+
281
+ // if *all* the error flags are clear, then indicate that we can submit
282
+ for (var err in itemFormErrors)
283
+ if (err != "item_description" && itemFormErrors[err] != false){
284
+ makeButtonSeemDisabled(itemSubmit);
285
+ return;
286
+ }
287
+ makeButtonSeemEnabled(itemSubmit);
288
+ }
289
+
290
+
291
+ function onfocusCommonBehavior(elem){
292
+ var eId = elem.id;
293
+ var c;
294
+ for (c=0; c < requiredItemElements.length &&
295
+ eId != controlNamePrefix + "item_" + requiredItemElements[c];
296
+ c++)
297
+ ;
298
+
299
+ if (c >= requiredItemElements.length)
300
+ return; // Hmmmm..... maybe not
301
+
302
+ var lastToCheck = c-1;
303
+ var errFlag = false;
304
+ c = thereIsATypeControl ? 0 : 1;
305
+ for (; c <= lastToCheck; c++){
306
+ var ck = $(controlNamePrefix + "item_" + requiredItemElements[c]);
307
+ if (ck.value == null || ck.value == ""){
308
+
309
+ itemFormErrors["item_" + requiredItemElements[c]] = true;
310
+ flagItemAsRequired(requiredItemElements[c]);
311
+
312
+ if (c < requiredItemElements.length-2)
313
+ errFlag = true;
314
+ }
315
+ else
316
+ itemFormErrors["item_" + requiredItemElements[c]] = false;
317
+ }
318
+
319
+ if (errFlag)
320
+ makeButtonSeemDisabled(itemSubmit);
321
+
322
+ // refresh everything
323
+ if (thereIsATypeControl)
324
+ maybeClearIcon('sti_type');
325
+ maybeClearIcon('title');
326
+ maybeClearIcon('name');
327
+ maybeClearIcon('description');
328
+ maybeCheckNameUniqueness(nameAjaxStart);
329
+ }
330
+
331
+ function checkFieldRequired(f){
332
+ var idStr = f.id;
333
+ if (!creatingNewItem)
334
+ idStr = idStr.replace(new RegExp(controlNamePrefix), "");
335
+ var name = idStr.match(/item_(.+)$/)[1];
336
+
337
+ if (f.value == null || f.value == ""){
338
+ flagItemAsRequired(name);
339
+ itemFormErrors[idStr] = true;
340
+ }
341
+ else {
342
+ var req = $(name + "_required");
343
+ if ( req != null )
344
+ req.className = "";
345
+ else
346
+ $(name + "_recommended").className = "";
347
+
348
+ itemFormErrors[idStr] = false;
349
+ }
350
+ }
351
+
352
+ function checkFieldLength(elem, index){
353
+ var name = elem.id.match(/item_(.+)$/)[1];
354
+
355
+ if (elem.value.length > maxLengths[index]){
356
+ $(name + '_too_long').className = "helpTextFlagged";
357
+ itemFormErrors['length_' + name] = true;
358
+ $(name + "_error_icon").src = "/images/error_error_icon.png";
359
+ }
360
+ else {
361
+ $(name + '_too_long').className = "";
362
+ itemFormErrors['length_' + name] = false;
363
+ }
364
+ }
365
+
366
+
367
+ function genDialog(){
368
+ var newDialogText = "<p>";
369
+ var accum = false;
370
+
371
+ for (var c=0; c < requiredItemElements.length-2; c++){
372
+ if (itemFormErrors["item_" + requiredItemElements[c]] == true){
373
+ accum = true;
374
+ newDialogText += "The " + itemElementNames[c] + " is required. ";
375
+ }
376
+ }
377
+ for (var c=1; c < requiredItemElements.length-1; c++){
378
+ if (itemFormErrors["length_" + requiredItemElements[c]] == true){
379
+ accum = true;
380
+ newDialogText += "The " + itemElementNames[c] + " field must be " +
381
+ maxLengths[c] + " or fewer characters. ";
382
+ }
383
+ }
384
+
385
+ if (accum){
386
+ newDialogText += "</p>";
387
+ var titleText = creatingNewItem ?
388
+ "Can't create this item yet" :
389
+ "Can't update this item";
390
+ Modalbox.show(newDialogText,
391
+ { title: titleText,
392
+ slideDownDuration: 0.25, slideUpDuration: 0.1 } );
393
+ }
394
+ return accum;
395
+ }
396
+
397
+
398
+
399
+ function clearNameUniquenessIndicators(){
400
+ $('name_must_be_unique').className = "";
401
+ $('name_is_unique').className = "confirmationTextInvisible";
402
+ $('name_status_icon').src = '/images/blank_status_icon.png';
403
+ }
404
+ function nameUCheckSuccess(transport){
405
+ ajaxRequestInProgress = null;
406
+ $('name_must_be_unique').className = "helpTextFlagged";
407
+ $('name_status_icon').src = '/images/error_status_icon.png';
408
+ itemFormErrors["unique_name"] = true;
409
+ makeButtonSeemDisabled(itemSubmit);
410
+ }
411
+ function nameUCheckFailure(transport){
412
+ ajaxRequestInProgress = null;
413
+ if (transport.status == 404){
414
+ $('name_is_unique').className = "confirmationTextShow";
415
+ $('name_status_icon').src = '/images/good_status_icon.png';
416
+ }
417
+ else
418
+ $('name_status_icon').src = '/images/blank_status_icon.png';
419
+ }
420
+ function launchNameUniquenessCheck(){
421
+ // we only have one timer ever, and this call shows it just expired, so...
422
+ uniquenessTimerId = -1;
423
+
424
+ var l = window.location;
425
+ var lookup = l.protocol + "//" + l.hostname + ":" + l.port + '/items/lookup';
426
+ ajaxRequestInProgress = new Ajax.Request(
427
+ lookup, {
428
+ method: 'get', parameters: "name=" + $F(controlNamePrefix + 'item_name'),
429
+ onSuccess: nameUCheckSuccess, onFailure: nameUCheckFailure
430
+ });
431
+
432
+ $('name_status_icon').src = '/images/working_status_icon.gif';
433
+ }
434
+ function maybeCheckNameUniqueness(delay){
435
+ var name = $(controlNamePrefix + 'item_name');
436
+
437
+ if (name.value != valueWhenLastChecked){
438
+ valueWhenLastChecked = name.value;
439
+
440
+ if (uniquenessTimerId != -1)
441
+ clearTimeout(uniquenessTimerId);
442
+ uniquenessTimerId = -1;
443
+ if (ajaxRequestInProgress != null)
444
+ ajaxRequestInProgress.transport.abort();
445
+ ajaxRequestInProgress = null;
446
+
447
+ clearNameUniquenessIndicators();
448
+
449
+ var old = itemFormErrors["unique_name"];
450
+ itemFormErrors["unique_name"] = false;
451
+ if (old)
452
+ maybeClearIcon('name');
453
+
454
+ var mtch = $('name_error_icon').src.match(/error_error_icon/);
455
+ if (name.value != null && name.value != "" &&
456
+ name.value != originalItemName &&
457
+ (mtch == null || mtch.length == 0)){
458
+ if (delay > 0)
459
+ uniquenessTimerId = setTimeout(launchNameUniquenessCheck, delay);
460
+ else
461
+ launchNameUniquenessCheck();
462
+ }
463
+ }
464
+ }
465
+
466
+
467
+
468
+ function getCurrentType(){
469
+ return $('item_sti_type').value;
470
+ }
471
+
472
+
473
+
474
+ function okToSubmitItemForm(){
475
+ onfocusCommonBehavior(itemSubmit);
476
+ var errors = genDialog();
477
+
478
+ if (errors)
479
+ makeButtonSeemDisabled(itemSubmit);
480
+ else
481
+ makeButtonSeemEnabled(itemSubmit);
482
+
483
+ return !errors;
484
+ }
485
+
486
+ // function to highlight help text based on Type <select> element state
487
+ function typeSelectOnchange(){
488
+ var sel = $('item_sti_type');
489
+ var tags = [ "category_title", "category_desc",
490
+ "individual_title", "individual_desc",
491
+ "property_title", "property_desc" ];
492
+
493
+ if ($(tags[0]) == null) // this version of form w/o explanatory text
494
+ return;
495
+
496
+ for (var c=0; c != tags.length; c++)
497
+ $(tags[c]).className = "";
498
+
499
+ if (sel.value == "CategoryItem"){
500
+ $(tags[0]).className = "titleSelectedItemDescription";
501
+ $(tags[1]).className = "bodySelectedItemDescription";
502
+ }
503
+ else if (sel.value == "IndividualItem"){
504
+ $(tags[2]).className = "titleSelectedItemDescription";
505
+ $(tags[3]).className = "bodySelectedItemDescription";
506
+ }
507
+ else if (sel.value == "PropertyItem"){
508
+ $(tags[4]).className = "titleSelectedItemDescription";
509
+ $(tags[5]).className = "bodySelectedItemDescription";
510
+ }
511
+ }