knitkit 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.md +6 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/knitkit/application.js +9 -0
  5. data/app/assets/stylesheets/knitkit/application.css +7 -0
  6. data/app/controllers/knitkit/articles_controller.rb +7 -0
  7. data/app/controllers/knitkit/base_controller.rb +45 -0
  8. data/app/controllers/knitkit/blogs_controller.rb +27 -0
  9. data/app/controllers/knitkit/comments_controller.rb +18 -0
  10. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +135 -0
  11. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +144 -0
  12. data/app/controllers/knitkit/erp_app/desktop/comments_controller.rb +43 -0
  13. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +27 -0
  14. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +145 -0
  15. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +28 -0
  16. data/app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb +68 -0
  17. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +20 -0
  18. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +272 -0
  19. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +135 -0
  20. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +177 -0
  21. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +143 -0
  22. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +116 -0
  23. data/app/controllers/knitkit/unauthorized_controller.rb +8 -0
  24. data/app/controllers/knitkit/website_sections_controller.rb +17 -0
  25. data/app/helpers/application_helper.rb +132 -0
  26. data/app/models/article.rb +14 -0
  27. data/app/models/blog.rb +21 -0
  28. data/app/models/comment.rb +24 -0
  29. data/app/models/content.rb +158 -0
  30. data/app/models/extensions/user.rb +5 -0
  31. data/app/models/published_element.rb +9 -0
  32. data/app/models/published_website.rb +118 -0
  33. data/app/models/theme.rb +239 -0
  34. data/app/models/website.rb +457 -0
  35. data/app/models/website_host.rb +3 -0
  36. data/app/models/website_inquiry.rb +11 -0
  37. data/app/models/website_inquiry_mailer.rb +12 -0
  38. data/app/models/website_nav.rb +17 -0
  39. data/app/models/website_nav_item.rb +21 -0
  40. data/app/models/website_section.rb +152 -0
  41. data/app/models/website_section_content.rb +4 -0
  42. data/app/views/knitkit/articles/index.html.erb +3 -0
  43. data/app/views/knitkit/articles/show.html.erb +4 -0
  44. data/app/views/knitkit/blogs/_add_comment.html.erb +28 -0
  45. data/app/views/knitkit/blogs/_comment.html.erb +8 -0
  46. data/app/views/knitkit/blogs/index.html.erb +51 -0
  47. data/app/views/knitkit/blogs/index.rss.builder +23 -0
  48. data/app/views/knitkit/blogs/show.html.erb +22 -0
  49. data/app/views/knitkit/unauthorized/index.html.erb +4 -0
  50. data/app/views/knitkit/website_sections/index.html.erb +6 -0
  51. data/app/views/layouts/knitkit/base.html.erb +59 -0
  52. data/app/views/menus/knitkit/_default_menu.html.erb +23 -0
  53. data/app/views/menus/knitkit/_default_section_menu.html.erb +27 -0
  54. data/app/views/menus/knitkit/_default_sub_menu.html.erb +45 -0
  55. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +49 -0
  56. data/app/views/shared/knitkit/_bread_crumb.html.erb +7 -0
  57. data/app/views/shared/knitkit/_footer.html.erb +3 -0
  58. data/app/views/website_inquiry_mailer/inquiry.erb +3 -0
  59. data/app/widgets/contact_us/base.rb +86 -0
  60. data/app/widgets/contact_us/javascript/contact_us.js +13 -0
  61. data/app/widgets/contact_us/views/_contact_form.html.erb +36 -0
  62. data/app/widgets/contact_us/views/error.html.erb +10 -0
  63. data/app/widgets/contact_us/views/index.html.erb +1 -0
  64. data/app/widgets/contact_us/views/layouts/base.html.erb +7 -0
  65. data/app/widgets/contact_us/views/success.html.erb +4 -0
  66. data/app/widgets/google_map/base.rb +48 -0
  67. data/app/widgets/google_map/javascript/google_map.js +174 -0
  68. data/app/widgets/google_map/views/index.html.erb +41 -0
  69. data/app/widgets/login/base.rb +61 -0
  70. data/app/widgets/login/javascript/login.js +162 -0
  71. data/app/widgets/login/views/index.html.erb +37 -0
  72. data/app/widgets/login/views/layouts/base.html.erb +14 -0
  73. data/app/widgets/login/views/login_header.html.erb +9 -0
  74. data/app/widgets/login/views/reset_password.html.erb +26 -0
  75. data/app/widgets/manage_profile/base.rb +327 -0
  76. data/app/widgets/manage_profile/javascript/manage_profile.js +11 -0
  77. data/app/widgets/manage_profile/views/_contact_information_form.html.erb +180 -0
  78. data/app/widgets/manage_profile/views/_password_form.html.erb +20 -0
  79. data/app/widgets/manage_profile/views/_user_information_form.html.erb +30 -0
  80. data/app/widgets/manage_profile/views/contact_type_in_use.html.erb +4 -0
  81. data/app/widgets/manage_profile/views/default_type_error.html.erb +5 -0
  82. data/app/widgets/manage_profile/views/error.html.erb +3 -0
  83. data/app/widgets/manage_profile/views/index.html.erb +46 -0
  84. data/app/widgets/manage_profile/views/layouts/base.html.erb +1 -0
  85. data/app/widgets/manage_profile/views/password_blank.html.erb +4 -0
  86. data/app/widgets/manage_profile/views/password_invalid.html.erb +4 -0
  87. data/app/widgets/manage_profile/views/password_success.html.erb +3 -0
  88. data/app/widgets/manage_profile/views/success.html.erb +3 -0
  89. data/app/widgets/reset_password/base.rb +42 -0
  90. data/app/widgets/reset_password/javascript/reset_password.js +13 -0
  91. data/app/widgets/reset_password/views/index.html.erb +31 -0
  92. data/app/widgets/reset_password/views/layouts/base.html.erb +1 -0
  93. data/app/widgets/search/base.rb +80 -0
  94. data/app/widgets/search/javascript/search.js +31 -0
  95. data/app/widgets/search/views/_search.html.erb +39 -0
  96. data/app/widgets/search/views/index.html.erb +3 -0
  97. data/app/widgets/search/views/layouts/base.html.erb +24 -0
  98. data/app/widgets/search/views/show.html.erb +48 -0
  99. data/app/widgets/signup/base.rb +72 -0
  100. data/app/widgets/signup/javascript/signup.js +13 -0
  101. data/app/widgets/signup/views/_signup_form.html.erb +36 -0
  102. data/app/widgets/signup/views/error.html.erb +11 -0
  103. data/app/widgets/signup/views/index.html.erb +1 -0
  104. data/app/widgets/signup/views/layouts/base.html.erb +7 -0
  105. data/app/widgets/signup/views/success.html.erb +4 -0
  106. data/config/environment.rb +0 -0
  107. data/config/routes.rb +41 -0
  108. data/db/data_migrations/20110509223702_add_publisher_role.rb +11 -0
  109. data/db/data_migrations/20110816153456_add_knitkit_application.rb +31 -0
  110. data/db/data_migrations/upgrade/20111011203718_create_paths_for_sections.rb +13 -0
  111. data/db/data_migrations/upgrade/20111216192114_add_secured_models_to_menu_items.rb +18 -0
  112. data/db/data_migrations/upgrade/20111216202819_set_contents_iid_to_permalink_where_null.rb +12 -0
  113. data/db/migrate/20110211002317_setup_knitkit.rb +259 -0
  114. data/db/migrate/upgrade/20111014190442_update_contents.rb +25 -0
  115. data/db/migrate/upgrade/20111014201502_add_published_by_to_published_elements.rb +22 -0
  116. data/db/migrate/upgrade/20111017133851_add_iid_to_section.rb +21 -0
  117. data/db/migrate/upgrade/20111027145006_add_in_menu_to_section.rb +19 -0
  118. data/lib/knitkit.rb +12 -0
  119. data/lib/knitkit/engine.rb +26 -0
  120. data/lib/knitkit/extensions.rb +18 -0
  121. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +88 -0
  122. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +28 -0
  123. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +38 -0
  124. data/lib/knitkit/extensions/active_record/theme_support/has_many_themes.rb +34 -0
  125. data/lib/knitkit/extensions/compass/widgets/base.rb +53 -0
  126. data/lib/knitkit/extensions/core/array.rb +5 -0
  127. data/lib/knitkit/extensions/railties/action_view.rb +187 -0
  128. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +198 -0
  129. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +44 -0
  130. data/lib/knitkit/routing_filter/section_router.rb +55 -0
  131. data/lib/knitkit/syntax_validator.rb +32 -0
  132. data/lib/knitkit/version.rb +3 -0
  133. data/lib/tasks/knitkit_tasks.rake +4 -0
  134. data/public/images/knitkit/bullet.png +0 -0
  135. data/public/images/knitkit/content.png +0 -0
  136. data/public/images/knitkit/footer.png +0 -0
  137. data/public/images/knitkit/graphic.png +0 -0
  138. data/public/images/knitkit/greyFadeDown.png +0 -0
  139. data/public/images/knitkit/link.png +0 -0
  140. data/public/images/knitkit/logo.png +0 -0
  141. data/public/images/knitkit/menu.png +0 -0
  142. data/public/images/knitkit/menu_select.png +0 -0
  143. data/public/images/knitkit/search.png +0 -0
  144. data/public/javascripts/datepicker.js +440 -0
  145. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +473 -0
  146. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +576 -0
  147. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +217 -0
  148. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +26 -0
  149. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +109 -0
  150. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +30 -0
  151. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +160 -0
  152. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +46 -0
  153. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +46 -0
  154. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +92 -0
  155. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +220 -0
  156. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +613 -0
  157. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +573 -0
  158. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +664 -0
  159. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +2161 -0
  160. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +52 -0
  161. data/public/stylesheets/datepicker.css +121 -0
  162. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +114 -0
  163. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +219 -0
  164. data/public/stylesheets/knitkit/style.css +394 -0
  165. metadata +289 -0
@@ -0,0 +1,44 @@
1
+ module ActionView
2
+ class ThemeFileResolver < OptimizedFileSystemResolver
3
+ def cached(key, path_info, details, locals) #:nodoc:
4
+ name, prefix, partial = path_info
5
+ locals = sort_locals(locals)
6
+
7
+ if key && caching?
8
+ if @cached[key][name][prefix][partial][locals].nil? or @cached[key][name][prefix][partial][locals].empty?
9
+ @cached[key][name][prefix][partial][locals] = decorate(yield, path_info, details, locals)
10
+ else
11
+ @cached[key][name][prefix][partial][locals].each do |template|
12
+ last_update = mtime(template.identifier)
13
+ if last_update > template.updated_at
14
+ @cached[key][name][prefix][partial][locals].delete_if{|item| item.identifier == template.identifier}
15
+ @cached[key][name][prefix][partial][locals] << build_template(template.identifier, template.virtual_path, (details[:formats] || [:html] if template.formats.empty?), template.locals)
16
+ end
17
+ end
18
+ @cached[key][name][prefix][partial][locals]
19
+ end
20
+ else
21
+ fresh = decorate(yield, path_info, details, locals)
22
+ return fresh unless key
23
+
24
+ scope = @cached[key][name][prefix][partial]
25
+ cache = scope[locals]
26
+ mtime = cache && cache.map(&:updated_at).max
27
+
28
+ if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime }
29
+ scope[locals] = fresh
30
+ else
31
+ cache
32
+ end
33
+ end
34
+ end
35
+
36
+ protected
37
+
38
+ def build_template(p, virtual_path, formats, locals=nil)
39
+ handler, format = extract_handler_and_format(p, formats)
40
+ contents = File.open(p, "rb") { |io| io.read }
41
+ Template.new(contents, p, handler, :virtual_path => virtual_path, :format => format, :updated_at => mtime(p), :locals => locals)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,55 @@
1
+ # If the path is, aside from a slash and an optional locale, the leftmost part
2
+ # of the path, replace it by "sections/:id" segments.
3
+
4
+ module RoutingFilter
5
+ class SectionRouter < Filter
6
+ def around_recognize(path, env, &block)
7
+ website = Website.find_by_host(env["HTTP_HOST"])
8
+ paths = paths_for_website(website)
9
+ if path !~ %r(^/([\w]{2,4}/)?admin) and !paths.empty? and path =~ recognize_pattern(paths)
10
+ if section = website_section_by_path(website, $2)
11
+ type = section.type.pluralize.downcase
12
+ path.sub! %r(^/([\w]{2,4}/)?(#{paths})(?=/|\.|$)), "/#{$1}#{type}/#{section.id}#{$3}"
13
+ end
14
+ end
15
+ yield
16
+ end
17
+
18
+ def around_generate(params, &block)
19
+ yield.tap do |path|
20
+ result = result.first if result.is_a?(Array)
21
+ if result !~ %r(^/([\w]{2,4}/)?admin) and result =~ generate_pattern
22
+ section = WebsiteSection.find $2.to_i
23
+ result.sub! "#{$1}/#{$2}", "#{section.path[1..section.path.length]}#{$3}"
24
+ end
25
+ end
26
+ end
27
+
28
+ protected
29
+ def paths_for_website(website)
30
+ website ? website.all_section_paths.map{|path| path[1..path.length]}.sort{|a, b| b.size <=> a.size }.join('|') : []
31
+ end
32
+
33
+ def website_section_by_path(website, path)
34
+ path = "/#{path}"
35
+ valid_section = website.website_sections.detect{|website_section| website_section.path == path }
36
+ if valid_section.nil?
37
+ website.website_sections.each do |website_section|
38
+ valid_section = website_section.child_by_path(path)
39
+ break unless valid_section.nil?
40
+ end
41
+ end
42
+
43
+ valid_section
44
+ end
45
+
46
+ def recognize_pattern(paths)
47
+ %r(^/([\w]{2,4}/)?(#{paths})(?=/|\.|$))
48
+ end
49
+
50
+ def generate_pattern
51
+ types = WebsiteSection.types.map{|type| type.downcase.pluralize }.join('|')
52
+ %r((#{types})/([\w]+(/?))(\.?)) # ?(?=\b)?
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,32 @@
1
+ module Knitkit
2
+ class SyntaxValidator
3
+ class << self
4
+
5
+ def validate_content(file_type, content)
6
+ case file_type.to_sym
7
+ when :erb
8
+ validate_erb(content)
9
+ else
10
+ return nil
11
+ end
12
+ end
13
+
14
+ def validate_file(file)
15
+ #stubbed for later development
16
+ end
17
+
18
+ private
19
+
20
+ def validate_erb(contents)
21
+ begin
22
+ ActionView::Template::Handlers::Erubis.new(contents).result
23
+ rescue SyntaxError=>ex
24
+ ex.message
25
+ rescue Exception=>ex
26
+ nil
27
+ end
28
+ end
29
+
30
+ end
31
+ end#SyntaxValidator
32
+ end#Knitkit
@@ -0,0 +1,3 @@
1
+ module Knitkit
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :knitkit do
3
+ # # Task goes here
4
+ # end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,440 @@
1
+ var datePickerDivID = "datepicker";
2
+ var iFrameDivID = "datepickeriframe";
3
+
4
+ var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
5
+ var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
6
+ var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
7
+ var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
8
+ var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
9
+ var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
10
+
11
+ // these variables define the date formatting we're expecting and outputting.
12
+ // If you want to use a different format by default, change the defaultDateSeparator
13
+ // and defaultDateFormat variables either here or on your HTML page.
14
+ var defaultDateSeparator = "/"; // common values would be "/" or "."
15
+ var defaultDateFormat = "mdy" // valid values are "mdy", "dmy", and "ymd"
16
+ var dateSeparator = defaultDateSeparator;
17
+ var dateFormat = defaultDateFormat;
18
+
19
+ /**
20
+ This is the main function you'll call from the onClick event of a button.
21
+ Normally, you'll have something like this on your HTML page:
22
+
23
+ Start Date: <input name="StartDate">
24
+ <input type=button value="select" onclick="displayDatePicker('StartDate');">
25
+
26
+ That will cause the datepicker to be displayed beneath the StartDate field and
27
+ any date that is chosen will update the value of that field. If you'd rather have the
28
+ datepicker display beneath the button that was clicked, you can code the button
29
+ like this:
30
+
31
+ <input type=button value="select" onclick="displayDatePicker('StartDate', this);">
32
+
33
+ So, pretty much, the first argument (dateFieldName) is a string representing the
34
+ name of the field that will be modified if the user picks a date, and the second
35
+ argument (displayBelowThisObject) is optional and represents an actual node
36
+ on the HTML document that the datepicker should be displayed below.
37
+
38
+ In version 1.1 of this code, the dtFormat and dtSep variables were added, allowing
39
+ you to use a specific date format or date separator for a given call to this function.
40
+ Normally, you'll just want to set these defaults globally with the defaultDateSeparator
41
+ and defaultDateFormat variables, but it doesn't hurt anything to add them as optional
42
+ parameters here. An example of use is:
43
+
44
+ <input type=button value="select" onclick="displayDatePicker('StartDate', false, 'dmy', '.');">
45
+
46
+ This would display the datepicker beneath the StartDate field (because the
47
+ displayBelowThisObject parameter was false), and update the StartDate field with
48
+ the chosen value of the datepicker using a date format of dd.mm.yyyy
49
+ */
50
+ function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep)
51
+ {
52
+ var targetDateField = document.getElementsByName (dateFieldName).item(0);
53
+
54
+ // if we weren't told what node to display the datepicker beneath, just display it
55
+ // beneath the date field we're updating
56
+ if (!displayBelowThisObject)
57
+ displayBelowThisObject = targetDateField;
58
+
59
+ // if a date separator character was given, update the dateSeparator variable
60
+ if (dtSep)
61
+ dateSeparator = dtSep;
62
+ else
63
+ dateSeparator = defaultDateSeparator;
64
+
65
+ // if a date format was given, update the dateFormat variable
66
+ if (dtFormat)
67
+ dateFormat = dtFormat;
68
+ else
69
+ dateFormat = defaultDateFormat;
70
+
71
+ var x = displayBelowThisObject.offsetLeft;
72
+ var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
73
+
74
+ // deal with elements inside tables and such
75
+ var parent = displayBelowThisObject;
76
+ while (parent.offsetParent) {
77
+ parent = parent.offsetParent;
78
+ x += parent.offsetLeft;
79
+ y += parent.offsetTop ;
80
+ }
81
+
82
+ drawDatePicker(targetDateField, x, y);
83
+ }
84
+
85
+
86
+ /**
87
+ Draw the datepicker object (which is just a table with calendar elements) at the
88
+ specified x and y coordinates, using the targetDateField object as the input tag
89
+ that will ultimately be populated with a date.
90
+
91
+ This function will normally be called by the displayDatePicker function.
92
+ */
93
+ function drawDatePicker(targetDateField, x, y)
94
+ {
95
+ var dt = getFieldDate(targetDateField.value );
96
+
97
+ // the datepicker table will be drawn inside of a <div> with an ID defined by the
98
+ // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
99
+ // document we're working with, add one.
100
+ if (!document.getElementById(datePickerDivID)) {
101
+ // don't use innerHTML to update the body, because it can cause global variables
102
+ // that are currently pointing to objects on the page to have bad references
103
+ //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
104
+ var newNode = document.createElement("div");
105
+ newNode.setAttribute("id", datePickerDivID);
106
+ newNode.setAttribute("class", "dpDiv");
107
+ newNode.setAttribute("style", "visibility: hidden;");
108
+ document.body.appendChild(newNode);
109
+ }
110
+
111
+ // move the datepicker div to the proper x,y coordinate and toggle the visiblity
112
+ var pickerDiv = document.getElementById(datePickerDivID);
113
+ pickerDiv.style.position = "absolute";
114
+ pickerDiv.style.left = x + "px";
115
+ pickerDiv.style.top = y + "px";
116
+ pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
117
+ pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
118
+ pickerDiv.style.zIndex = 10000;
119
+
120
+ // draw the datepicker table
121
+ refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
122
+ }
123
+
124
+
125
+ /**
126
+ This is the function that actually draws the datepicker calendar.
127
+ */
128
+ function refreshDatePicker(dateFieldName, year, month, day)
129
+ {
130
+ // if no arguments are passed, use today's date; otherwise, month and year
131
+ // are required (if a day is passed, it will be highlighted later)
132
+ var thisDay = new Date();
133
+
134
+ if ((month >= 0) && (year > 0)) {
135
+ thisDay = new Date(year, month, 1);
136
+ } else {
137
+ day = thisDay.getDate();
138
+ thisDay.setDate(1);
139
+ }
140
+
141
+ // the calendar will be drawn as a table
142
+ // you can customize the table elements with a global CSS style sheet,
143
+ // or by hardcoding style and formatting elements below
144
+ var crlf = "\r\n";
145
+ var TABLE = "<table cols=7 class='dpTable'>" + crlf;
146
+ var xTABLE = "</table>" + crlf;
147
+ var TR = "<tr class='dpTR'>";
148
+ var TR_title = "<tr class='dpTitleTR'>";
149
+ var TR_days = "<tr class='dpDayTR'>";
150
+ var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
151
+ var xTR = "</tr>" + crlf;
152
+ var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' "; // leave this tag open, because we'll be adding an onClick event
153
+ var TD_title = "<td colspan=5 class='dpTitleTD'>";
154
+ var TD_buttons = "<td class='dpButtonTD'>";
155
+ var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
156
+ var TD_days = "<td class='dpDayTD'>";
157
+ var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' "; // leave this tag open, because we'll be adding an onClick event
158
+ var xTD = "</td>" + crlf;
159
+ var DIV_title = "<div class='dpTitleText'>";
160
+ var DIV_selected = "<div class='dpDayHighlight'>";
161
+ var xDIV = "</div>";
162
+
163
+ // start generating the code for the calendar table
164
+ var html = TABLE;
165
+
166
+ // this is the title bar, which displays the month and the buttons to
167
+ // go back to a previous month or forward to the next month
168
+ html += TR_title;
169
+ html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
170
+ html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
171
+ html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
172
+ html += xTR;
173
+
174
+ // this is the row that indicates which day of the week we're on
175
+ html += TR_days;
176
+ for(i = 0; i < dayArrayShort.length; i++)
177
+ html += TD_days + dayArrayShort[i] + xTD;
178
+ html += xTR;
179
+
180
+ // now we'll start populating the table with days of the month
181
+ html += TR;
182
+
183
+ // first, the leading blanks
184
+ for (i = 0; i < thisDay.getDay(); i++)
185
+ html += TD + "&nbsp;" + xTD;
186
+
187
+ // now, the days of the month
188
+ do {
189
+ dayNum = thisDay.getDate();
190
+ TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
191
+
192
+ if (dayNum == day)
193
+ html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
194
+ else
195
+ html += TD + TD_onclick + dayNum + xTD;
196
+
197
+ // if this is a Saturday, start a new row
198
+ if (thisDay.getDay() == 6)
199
+ html += xTR + TR;
200
+
201
+ // increment the day
202
+ thisDay.setDate(thisDay.getDate() + 1);
203
+ } while (thisDay.getDate() > 1)
204
+
205
+ // fill in any trailing blanks
206
+ if (thisDay.getDay() > 0) {
207
+ for (i = 6; i > thisDay.getDay(); i--)
208
+ html += TD + "&nbsp;" + xTD;
209
+ }
210
+ html += xTR;
211
+
212
+ // add a button to allow the user to easily return to today, or close the calendar
213
+ var today = new Date();
214
+ var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
215
+ html += TR_todaybutton + TD_todaybutton;
216
+ html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>this month</button> ";
217
+ html += "<button class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\");'>close</button>";
218
+ html += xTD + xTR;
219
+
220
+ // and finally, close the table
221
+ html += xTABLE;
222
+
223
+ document.getElementById(datePickerDivID).innerHTML = html;
224
+ // add an "iFrame shim" to allow the datepicker to display above selection lists
225
+ adjustiFrame();
226
+ }
227
+
228
+
229
+ /**
230
+ Convenience function for writing the code for the buttons that bring us back or forward
231
+ a month.
232
+ */
233
+ function getButtonCode(dateFieldName, dateVal, adjust, label)
234
+ {
235
+ var newMonth = (dateVal.getMonth () + adjust) % 12;
236
+ var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
237
+ if (newMonth < 0) {
238
+ newMonth += 12;
239
+ newYear += -1;
240
+ }
241
+
242
+ return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
243
+ }
244
+
245
+
246
+ /**
247
+ Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
248
+ variables at the beginning of this script library.
249
+ */
250
+ function getDateString(dateVal)
251
+ {
252
+ var dayString = "00" + dateVal.getDate();
253
+ var monthString = "00" + (dateVal.getMonth()+1);
254
+ dayString = dayString.substring(dayString.length - 2);
255
+ monthString = monthString.substring(monthString.length - 2);
256
+
257
+ switch (dateFormat) {
258
+ case "dmy" :
259
+ return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
260
+ case "ymd" :
261
+ return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
262
+ case "mdy" :
263
+ default :
264
+ return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
265
+ }
266
+ }
267
+
268
+
269
+ /**
270
+ Convert a string to a JavaScript Date object.
271
+ */
272
+ function getFieldDate(dateString)
273
+ {
274
+ var dateVal;
275
+ var dArray;
276
+ var d, m, y;
277
+
278
+ try {
279
+ dArray = splitDateString(dateString);
280
+ if (dArray) {
281
+ switch (dateFormat) {
282
+ case "dmy" :
283
+ d = parseInt(dArray[0], 10);
284
+ m = parseInt(dArray[1], 10) - 1;
285
+ y = parseInt(dArray[2], 10);
286
+ break;
287
+ case "ymd" :
288
+ d = parseInt(dArray[2], 10);
289
+ m = parseInt(dArray[1], 10) - 1;
290
+ y = parseInt(dArray[0], 10);
291
+ break;
292
+ case "mdy" :
293
+ default :
294
+ d = parseInt(dArray[1], 10);
295
+ m = parseInt(dArray[0], 10) - 1;
296
+ y = parseInt(dArray[2], 10);
297
+ break;
298
+ }
299
+ dateVal = new Date(y, m, d);
300
+ } else if (dateString) {
301
+ dateVal = new Date(dateString);
302
+ } else {
303
+ dateVal = new Date();
304
+ }
305
+ } catch(e) {
306
+ dateVal = new Date();
307
+ }
308
+
309
+ return dateVal;
310
+ }
311
+
312
+
313
+ /**
314
+ Try to split a date string into an array of elements, using common date separators.
315
+ If the date is split, an array is returned; otherwise, we just return false.
316
+ */
317
+ function splitDateString(dateString)
318
+ {
319
+ var dArray;
320
+ if (dateString.indexOf("/") >= 0)
321
+ dArray = dateString.split("/");
322
+ else if (dateString.indexOf(".") >= 0)
323
+ dArray = dateString.split(".");
324
+ else if (dateString.indexOf("-") >= 0)
325
+ dArray = dateString.split("-");
326
+ else if (dateString.indexOf("\\") >= 0)
327
+ dArray = dateString.split("\\");
328
+ else
329
+ dArray = false;
330
+
331
+ return dArray;
332
+ }
333
+
334
+ /**
335
+ Update the field with the given dateFieldName with the dateString that has been passed,
336
+ and hide the datepicker. If no dateString is passed, just close the datepicker without
337
+ changing the field value.
338
+
339
+ Also, if the page developer has defined a function called datePickerClosed anywhere on
340
+ the page or in an imported library, we will attempt to run that function with the updated
341
+ field as a parameter. This can be used for such things as date validation, setting default
342
+ values for related fields, etc. For example, you might have a function like this to validate
343
+ a start date field:
344
+
345
+ function datePickerClosed(dateField)
346
+ {
347
+ var dateObj = getFieldDate(dateField.value);
348
+ var today = new Date();
349
+ today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
350
+
351
+ if (dateField.name == "StartDate") {
352
+ if (dateObj < today) {
353
+ // if the date is before today, alert the user and display the datepicker again
354
+ alert("Please enter a date that is today or later");
355
+ dateField.value = "";
356
+ document.getElementById(datePickerDivID).style.visibility = "visible";
357
+ adjustiFrame();
358
+ } else {
359
+ // if the date is okay, set the EndDate field to 7 days after the StartDate
360
+ dateObj.setTime(dateObj.getTime() + (7 * 24 * 60 * 60 * 1000));
361
+ var endDateField = document.getElementsByName ("EndDate").item(0);
362
+ endDateField.value = getDateString(dateObj);
363
+ }
364
+ }
365
+ }
366
+
367
+ */
368
+ function updateDateField(dateFieldName, dateString)
369
+ {
370
+ var targetDateField = document.getElementsByName (dateFieldName).item(0);
371
+ if (dateString)
372
+ targetDateField.value = dateString;
373
+
374
+ var pickerDiv = document.getElementById(datePickerDivID);
375
+ pickerDiv.style.visibility = "hidden";
376
+ pickerDiv.style.display = "none";
377
+
378
+ adjustiFrame();
379
+ targetDateField.focus();
380
+
381
+ // after the datepicker has closed, optionally run a user-defined function called
382
+ // datePickerClosed, passing the field that was just updated as a parameter
383
+ // (note that this will only run if the user actually selected a date from the datepicker)
384
+ if ((dateString) && (typeof(datePickerClosed) == "function"))
385
+ datePickerClosed(targetDateField);
386
+ }
387
+
388
+
389
+ /**
390
+ Use an "iFrame shim" to deal with problems where the datepicker shows up behind
391
+ selection list elements, if they're below the datepicker. The problem and solution are
392
+ described at:
393
+
394
+ http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
395
+ http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
396
+ */
397
+ function adjustiFrame(pickerDiv, iFrameDiv)
398
+ {
399
+ // we know that Opera doesn't like something about this, so if we
400
+ // think we're using Opera, don't even try
401
+ var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
402
+ if (is_opera)
403
+ return;
404
+
405
+ // put a try/catch block around the whole thing, just in case
406
+ try {
407
+ if (!document.getElementById(iFrameDivID)) {
408
+ // don't use innerHTML to update the body, because it can cause global variables
409
+ // that are currently pointing to objects on the page to have bad references
410
+ //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
411
+ var newNode = document.createElement("iFrame");
412
+ newNode.setAttribute("id", iFrameDivID);
413
+ newNode.setAttribute("src", "javascript:false;");
414
+ newNode.setAttribute("scrolling", "no");
415
+ newNode.setAttribute ("frameborder", "0");
416
+ document.body.appendChild(newNode);
417
+ }
418
+
419
+ if (!pickerDiv)
420
+ pickerDiv = document.getElementById(datePickerDivID);
421
+ if (!iFrameDiv)
422
+ iFrameDiv = document.getElementById(iFrameDivID);
423
+
424
+ try {
425
+ iFrameDiv.style.position = "absolute";
426
+ iFrameDiv.style.width = pickerDiv.offsetWidth;
427
+ iFrameDiv.style.height = pickerDiv.offsetHeight ;
428
+ iFrameDiv.style.top = pickerDiv.style.top;
429
+ iFrameDiv.style.left = pickerDiv.style.left;
430
+ iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
431
+ iFrameDiv.style.visibility = pickerDiv.style.visibility ;
432
+ iFrameDiv.style.display = pickerDiv.style.display;
433
+ } catch(e) {
434
+ }
435
+
436
+ } catch (ee) {
437
+ }
438
+
439
+ }
440
+