creationix-milk 0.0.9 → 0.1.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.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/milk/application.rb +37 -16
- data/lib/milk/component.rb +23 -28
- data/lib/milk/field.rb +7 -18
- data/lib/milk/page.rb +19 -25
- data/lib/milk/tasks.rb +6 -7
- data/lib/milk.rb +64 -40
- data/milk.gemspec +56 -45
- data/site_template/Rakefile +5 -0
- data/site_template/bootstrap.rb +71 -0
- data/site_template/config.ru +1 -3
- data/site_template/{config → data/global}/foot.yaml +0 -0
- data/site_template/{config → data/global}/head.yaml +4 -4
- data/site_template/{pages → data/pages}/About.yaml +3 -3
- data/site_template/{pages → data/pages}/Home.yaml +4 -3
- data/site_template/{pages → data/pages}/News.yaml +3 -3
- data/site_template/{pages → data/pages}/NotFound.yaml +3 -3
- data/site_template/{pages → data/pages}/Products.yaml +3 -3
- data/site_template/lib/components/body.rb +6 -0
- data/site_template/lib/components/button.rb +19 -0
- data/site_template/lib/components/foot.rb +6 -0
- data/site_template/lib/components/head.rb +6 -0
- data/site_template/lib/fields/checkbox_field.rb +4 -0
- data/{lib/milk → site_template/lib}/fields/component_array.rb +0 -0
- data/site_template/lib/fields/dropdown_field.rb +4 -0
- data/{lib/milk → site_template/lib}/fields/image_chooser.rb +0 -0
- data/{lib/milk → site_template/lib}/fields/markdown_field.rb +0 -0
- data/{lib/milk → site_template/lib}/fields/page_chooser.rb +1 -1
- data/{lib/milk → site_template/lib}/fields/sprite_chooser.rb +1 -1
- data/{lib/milk → site_template/lib}/fields/text_field.rb +0 -0
- data/site_template/public/js/edit.js +121 -0
- data/site_template/public/js/form_validate.js +51 -0
- data/site_template/public/js/login.js +9 -0
- data/site_template/public/style/960.css +96 -0
- data/site_template/public/style/edit.css +29 -0
- data/site_template/public/style/login.css +12 -0
- data/site_template/public/style/reset.css +33 -0
- data/site_template/public/style/text.css +25 -0
- data/site_template/public/style/view.css +10 -0
- data/site_template/{design → templates}/960.sass +0 -0
- data/site_template/{design → templates/components}/body.haml +0 -0
- data/site_template/{design → templates/components}/button.haml +0 -0
- data/site_template/{design → templates/components}/foot.haml +0 -0
- data/site_template/{design → templates/components}/head.haml +0 -0
- data/site_template/templates/dependencies.haml +8 -0
- data/{lib/milk/fields/component.haml → site_template/templates/edit.component.haml} +0 -0
- data/site_template/templates/edit.haml +38 -0
- data/site_template/templates/edit.sass +91 -0
- data/site_template/templates/fields/checkbox_field.haml +1 -0
- data/{lib/milk → site_template/templates}/fields/component_array.haml +0 -0
- data/site_template/templates/fields/dropdown_field.haml +3 -0
- data/{lib/milk → site_template/templates}/fields/image_chooser.haml +0 -0
- data/{lib/milk → site_template/templates}/fields/markdown_field.haml +0 -0
- data/site_template/templates/fields/page_chooser.haml +3 -0
- data/{lib/milk → site_template/templates}/fields/sprite_chooser.haml +0 -0
- data/{lib/milk → site_template/templates}/fields/text_field.haml +0 -0
- data/site_template/templates/login.haml +37 -0
- data/site_template/templates/login.sass +35 -0
- data/site_template/{design/0-reset.sass → templates/reset.sass} +0 -0
- data/site_template/{design/1-text.sass → templates/text.sass} +0 -0
- data/site_template/{design/xhtml.haml → templates/view.haml} +2 -3
- data/site_template/{design/page.haml → templates/view.page.haml} +0 -0
- data/site_template/{design/head.sass → templates/view.sass} +10 -0
- metadata +56 -45
- data/lib/milk/fields/login.haml +0 -90
- data/lib/milk/fields/page_chooser.haml +0 -3
- data/lib/milk/fields/xhtml.haml +0 -253
- data/lib/milk/haxe.rb +0 -139
- data/site_template/config/config.yaml +0 -31
- data/site_template/config/users.yaml +0 -18
- data/site_template/design/body.rb +0 -4
- data/site_template/design/button.rb +0 -16
- data/site_template/design/foot.rb +0 -4
- data/site_template/design/foot.sass +0 -3
- data/site_template/design/head.rb +0 -4
- data/site_template/design/page.sass +0 -7
- data/site_template/design/sprites.sass +0 -0
data/milk.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{milk}
|
5
|
-
s.version = "0.0
|
5
|
+
s.version = "0.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Tim Caswell"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-28}
|
10
10
|
s.default_executable = %q{milk}
|
11
11
|
s.email = %q{tim@creationix.com}
|
12
12
|
s.executables = ["milk"]
|
@@ -26,62 +26,43 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/milk/application.rb",
|
27
27
|
"lib/milk/component.rb",
|
28
28
|
"lib/milk/field.rb",
|
29
|
-
"lib/milk/fields/component.haml",
|
30
|
-
"lib/milk/fields/component_array.haml",
|
31
|
-
"lib/milk/fields/component_array.rb",
|
32
|
-
"lib/milk/fields/image_chooser.haml",
|
33
|
-
"lib/milk/fields/image_chooser.rb",
|
34
|
-
"lib/milk/fields/login.haml",
|
35
|
-
"lib/milk/fields/markdown_field.haml",
|
36
|
-
"lib/milk/fields/markdown_field.rb",
|
37
|
-
"lib/milk/fields/page_chooser.haml",
|
38
|
-
"lib/milk/fields/page_chooser.rb",
|
39
|
-
"lib/milk/fields/sprite_chooser.haml",
|
40
|
-
"lib/milk/fields/sprite_chooser.rb",
|
41
|
-
"lib/milk/fields/text_field.haml",
|
42
|
-
"lib/milk/fields/text_field.rb",
|
43
|
-
"lib/milk/fields/xhtml.haml",
|
44
|
-
"lib/milk/haxe.rb",
|
45
29
|
"lib/milk/page.rb",
|
46
30
|
"lib/milk/tasks.rb",
|
47
31
|
"milk.gemspec",
|
48
32
|
"site_template/Rakefile",
|
33
|
+
"site_template/bootstrap.rb",
|
49
34
|
"site_template/config.ru",
|
50
|
-
"site_template/
|
51
|
-
"site_template/
|
52
|
-
"site_template/
|
53
|
-
"site_template/
|
54
|
-
"site_template/
|
55
|
-
"site_template/
|
56
|
-
"site_template/
|
57
|
-
"site_template/
|
58
|
-
"site_template/
|
59
|
-
"site_template/
|
60
|
-
"site_template/
|
61
|
-
"site_template/
|
62
|
-
"site_template/
|
63
|
-
"site_template/
|
64
|
-
"site_template/
|
65
|
-
"site_template/
|
66
|
-
"site_template/
|
67
|
-
"site_template/
|
68
|
-
"site_template/
|
69
|
-
"site_template/design/sprites.sass",
|
70
|
-
"site_template/design/xhtml.haml",
|
71
|
-
"site_template/pages/About.yaml",
|
72
|
-
"site_template/pages/Home.yaml",
|
73
|
-
"site_template/pages/News.yaml",
|
74
|
-
"site_template/pages/NotFound.yaml",
|
75
|
-
"site_template/pages/Products.yaml",
|
35
|
+
"site_template/data/global/foot.yaml",
|
36
|
+
"site_template/data/global/head.yaml",
|
37
|
+
"site_template/data/pages/About.yaml",
|
38
|
+
"site_template/data/pages/Home.yaml",
|
39
|
+
"site_template/data/pages/News.yaml",
|
40
|
+
"site_template/data/pages/NotFound.yaml",
|
41
|
+
"site_template/data/pages/Products.yaml",
|
42
|
+
"site_template/lib/components/body.rb",
|
43
|
+
"site_template/lib/components/button.rb",
|
44
|
+
"site_template/lib/components/foot.rb",
|
45
|
+
"site_template/lib/components/head.rb",
|
46
|
+
"site_template/lib/fields/checkbox_field.rb",
|
47
|
+
"site_template/lib/fields/component_array.rb",
|
48
|
+
"site_template/lib/fields/dropdown_field.rb",
|
49
|
+
"site_template/lib/fields/image_chooser.rb",
|
50
|
+
"site_template/lib/fields/markdown_field.rb",
|
51
|
+
"site_template/lib/fields/page_chooser.rb",
|
52
|
+
"site_template/lib/fields/sprite_chooser.rb",
|
53
|
+
"site_template/lib/fields/text_field.rb",
|
76
54
|
"site_template/public/cache/About/index.html",
|
77
55
|
"site_template/public/cache/Home/index.html",
|
78
56
|
"site_template/public/cache/News/index.html",
|
79
57
|
"site_template/public/cache/Products/index.html",
|
80
58
|
"site_template/public/favicon.ico",
|
81
59
|
"site_template/public/images/README.txt",
|
60
|
+
"site_template/public/js/edit.js",
|
61
|
+
"site_template/public/js/form_validate.js",
|
82
62
|
"site_template/public/js/jquery-1.3.2.min.js",
|
83
63
|
"site_template/public/js/jquery-ui-1.7.2.custom.min.js",
|
84
64
|
"site_template/public/js/jquery.json-1.3.min.js",
|
65
|
+
"site_template/public/js/login.js",
|
85
66
|
"site_template/public/robots.txt",
|
86
67
|
"site_template/public/skin/images/ui-bg_diagonals-thick_18_b81900_40x40.png",
|
87
68
|
"site_template/public/skin/images/ui-bg_diagonals-thick_20_666666_40x40.png",
|
@@ -98,7 +79,37 @@ Gem::Specification.new do |s|
|
|
98
79
|
"site_template/public/skin/images/ui-icons_ffd27a_256x240.png",
|
99
80
|
"site_template/public/skin/images/ui-icons_ffffff_256x240.png",
|
100
81
|
"site_template/public/skin/jquery-ui-1.7.2.custom.css",
|
82
|
+
"site_template/public/style/960.css",
|
83
|
+
"site_template/public/style/edit.css",
|
84
|
+
"site_template/public/style/login.css",
|
85
|
+
"site_template/public/style/reset.css",
|
101
86
|
"site_template/public/style/style.css",
|
87
|
+
"site_template/public/style/text.css",
|
88
|
+
"site_template/public/style/view.css",
|
89
|
+
"site_template/templates/960.sass",
|
90
|
+
"site_template/templates/components/body.haml",
|
91
|
+
"site_template/templates/components/button.haml",
|
92
|
+
"site_template/templates/components/foot.haml",
|
93
|
+
"site_template/templates/components/head.haml",
|
94
|
+
"site_template/templates/dependencies.haml",
|
95
|
+
"site_template/templates/edit.component.haml",
|
96
|
+
"site_template/templates/edit.haml",
|
97
|
+
"site_template/templates/edit.sass",
|
98
|
+
"site_template/templates/fields/checkbox_field.haml",
|
99
|
+
"site_template/templates/fields/component_array.haml",
|
100
|
+
"site_template/templates/fields/dropdown_field.haml",
|
101
|
+
"site_template/templates/fields/image_chooser.haml",
|
102
|
+
"site_template/templates/fields/markdown_field.haml",
|
103
|
+
"site_template/templates/fields/page_chooser.haml",
|
104
|
+
"site_template/templates/fields/sprite_chooser.haml",
|
105
|
+
"site_template/templates/fields/text_field.haml",
|
106
|
+
"site_template/templates/login.haml",
|
107
|
+
"site_template/templates/login.sass",
|
108
|
+
"site_template/templates/reset.sass",
|
109
|
+
"site_template/templates/text.sass",
|
110
|
+
"site_template/templates/view.haml",
|
111
|
+
"site_template/templates/view.page.haml",
|
112
|
+
"site_template/templates/view.sass",
|
102
113
|
"site_template/tmp/restart.txt",
|
103
114
|
"test/milk_test.rb",
|
104
115
|
"test/test_helper.rb"
|
@@ -107,7 +118,7 @@ Gem::Specification.new do |s|
|
|
107
118
|
s.homepage = %q{http://github.com/creationix/milk}
|
108
119
|
s.rdoc_options = ["--charset=UTF-8"]
|
109
120
|
s.require_paths = ["lib"]
|
110
|
-
s.required_ruby_version = Gem::Requirement.new(">= 1.
|
121
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.8")
|
111
122
|
s.rubyforge_project = %q{milk}
|
112
123
|
s.rubygems_version = %q{1.3.1}
|
113
124
|
s.summary = %q{Milk is a rack based content management system built for ease of use and simplicity. Milk tastes great with and without cookies.}
|
data/site_template/Rakefile
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
# This section is the milk configs for this local app
|
2
|
+
module Milk
|
3
|
+
|
4
|
+
SITE_DIR = File.absolute_path(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
# SECRET is the site specific key used to encrypt the cookies sent for authentication.
|
7
|
+
#
|
8
|
+
# It is very important that this key be both long and unique to each site you build.
|
9
|
+
#
|
10
|
+
# My method is to pick two secret passphrases and concatenating the md5 of them together
|
11
|
+
#
|
12
|
+
# >> require 'digest/md5'
|
13
|
+
# => true
|
14
|
+
# >> Digest::MD5.hexdigest("Milk") + Digest::MD5.hexdigest("Rocks")
|
15
|
+
# => "e89b2cbb7d11825a67459af2249064de5cdfbc0ea6e85d2cc3dd5ddec72ffe1a"
|
16
|
+
SECRET = "098f6bcd4621d373cade4e832627b4f6ad0234829205b9033196ba818f7a872b"
|
17
|
+
|
18
|
+
# USE_CACHE is an advanced option for sites that need super high performance. When
|
19
|
+
# this option is set to true, then every time a page is saved, a static html file is
|
20
|
+
# created and saved to [MILK_ROOT]/public/cache/[pagename]/index.html
|
21
|
+
#
|
22
|
+
# In order to use these cache files your apache or nginx server needs to have a rewrite
|
23
|
+
# rule that looks here first and uses the static files if they exist.
|
24
|
+
#
|
25
|
+
# As an example, here is the relevent part of my nginx config:
|
26
|
+
#
|
27
|
+
# # Enable loading page cache files directly
|
28
|
+
# rewrite ^/$ /cache/Home/index.html;
|
29
|
+
# rewrite ^((/[A-Z][A-Za-z]*)+)$ /cache/$1/index.html;
|
30
|
+
USE_CACHE = false
|
31
|
+
|
32
|
+
# This determines what resources depend on what. That way a page can specify only what it
|
33
|
+
# needs and the rest will be pulled in automatically.
|
34
|
+
# Full paths mean to include a file, module name means that module is a dependency.
|
35
|
+
DEPENDENCY_TREE = {
|
36
|
+
:view => ["/favicon.ico", "/style/reset.css", "/style/text.css", "/style/960.css", "/style/view.css"],
|
37
|
+
:jquery => ["/js/jquery-1.3.2.min.js"],
|
38
|
+
:jquery_ui => [:jquery, "/js/jquery-ui-1.7.2.custom.min.js", "/skin/jquery-ui-1.7.2.custom.css"],
|
39
|
+
:jquery_json => [:jquery, "/js/jquery.json-1.3.min.js"],
|
40
|
+
:form_validate => [:jquery, "/js/form_validate.js"],
|
41
|
+
:edit => [:view, :jquery_json, :jquery_ui, "/js/edit.js", "/style/edit.css"],
|
42
|
+
:login_form => [:view, :jquery_ui, "/js/login.js", "/style/login.css"]
|
43
|
+
}
|
44
|
+
|
45
|
+
# This sets the authorized users to the site. When we implement an interface to change these
|
46
|
+
# settings through the web, then we will move these to a seperate file.
|
47
|
+
#
|
48
|
+
# Hash is a simple md5 of the password for now, future versions of
|
49
|
+
# Milk may use something more secure.
|
50
|
+
#
|
51
|
+
# To create the md5 hash in irb do the following:
|
52
|
+
#
|
53
|
+
# >> require 'digest/md5'
|
54
|
+
# => true
|
55
|
+
# >> Digest::MD5.hexdigest("test")
|
56
|
+
# => "098f6bcd4621d373cade4e832627b4f6"
|
57
|
+
#
|
58
|
+
# Note the default login is admin@example.com/test
|
59
|
+
USERS = {
|
60
|
+
"admin@example.com" => { :name => "Sample Admin", :hash => "098f6bcd4621d373cade4e832627b4f6" }
|
61
|
+
}
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# This allows for local gems to be used if they exist
|
66
|
+
Dir.glob(Milk::SITE_DIR+"/vendor/*/lib").each do |path|
|
67
|
+
puts "Using local gem at #{path}"
|
68
|
+
$LOAD_PATH.unshift(path)
|
69
|
+
end
|
70
|
+
require 'milk'
|
71
|
+
|
data/site_template/config.ru
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'bootstrap'
|
2
2
|
|
3
|
-
# use Lock
|
4
3
|
if %w{rackup thin}.member?($0.rpartition('/').last)
|
5
4
|
puts "Running in development mode"
|
6
5
|
use ContentLength
|
@@ -10,7 +9,6 @@ if %w{rackup thin}.member?($0.rpartition('/').last)
|
|
10
9
|
Milk::Application.new
|
11
10
|
])
|
12
11
|
else
|
13
|
-
# When using passenger, require secure cookies and don't bother with static files
|
14
12
|
run Milk::Application.new(true)
|
15
13
|
end
|
16
14
|
|
File without changes
|
@@ -1,18 +1,18 @@
|
|
1
1
|
---
|
2
2
|
buttons:
|
3
|
-
- !ruby/object:Button
|
3
|
+
- !ruby/object:Milk::Components::Button
|
4
4
|
href: /Home
|
5
5
|
title: Home
|
6
6
|
description: Description of home page
|
7
|
-
- !ruby/object:Button
|
7
|
+
- !ruby/object:Milk::Components::Button
|
8
8
|
href: /News
|
9
9
|
title: News
|
10
10
|
description: Description of news page
|
11
|
-
- !ruby/object:Button
|
11
|
+
- !ruby/object:Milk::Components::Button
|
12
12
|
href: /Products
|
13
13
|
title: Products
|
14
14
|
description: Description of products page
|
15
|
-
- !ruby/object:Button
|
15
|
+
- !ruby/object:Milk::Components::Button
|
16
16
|
href: /About
|
17
17
|
title: About Us
|
18
18
|
description: Description of about page
|
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Milk::Page
|
2
2
|
components:
|
3
|
-
- !ruby/object:Head {}
|
3
|
+
- !ruby/object:Milk::Components::Head {}
|
4
4
|
|
5
|
-
- !ruby/object:Body
|
5
|
+
- !ruby/object:Milk::Components::Body
|
6
6
|
markdown: |-
|
7
7
|
# About Us
|
8
8
|
|
9
9
|
Description of about page
|
10
|
-
- !ruby/object:Foot {}
|
10
|
+
- !ruby/object:Milk::Components::Foot {}
|
11
11
|
|
12
12
|
title: About Us
|
13
13
|
keywords: ""
|
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Milk::Page
|
2
|
+
#comment
|
2
3
|
components:
|
3
|
-
- !ruby/object:Head {}
|
4
|
+
- !ruby/object:Milk::Components::Head {}
|
4
5
|
|
5
|
-
- !ruby/object:Body
|
6
|
+
- !ruby/object:Milk::Components::Body
|
6
7
|
markdown: |-
|
7
8
|
# Home
|
8
9
|
|
9
10
|
Description of home page
|
10
|
-
- !ruby/object:Foot {}
|
11
|
+
- !ruby/object:Milk::Components::Foot {}
|
11
12
|
|
12
13
|
title: Home
|
13
14
|
keywords: keywords, that, are, relevent, to, search, engines
|
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Milk::Page
|
2
2
|
components:
|
3
|
-
- !ruby/object:Head {}
|
3
|
+
- !ruby/object:Milk::Components::Head {}
|
4
4
|
|
5
|
-
- !ruby/object:Body
|
5
|
+
- !ruby/object:Milk::Components::Body
|
6
6
|
markdown: |-
|
7
7
|
# News
|
8
8
|
|
9
9
|
Description of news page
|
10
|
-
- !ruby/object:Foot {}
|
10
|
+
- !ruby/object:Milk::Components::Foot {}
|
11
11
|
|
12
12
|
title: News
|
13
13
|
keywords: ""
|
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Milk::Page
|
2
2
|
components:
|
3
|
-
- !ruby/object:Head {}
|
3
|
+
- !ruby/object:Milk::Components::Head {}
|
4
4
|
|
5
|
-
- !ruby/object:Body
|
5
|
+
- !ruby/object:Milk::Components::Body
|
6
6
|
markdown: |-
|
7
7
|
# 404 - Page not found
|
8
8
|
|
9
9
|
The page you were looking for was not found
|
10
|
-
- !ruby/object:Foot {}
|
10
|
+
- !ruby/object:Milk::Components::Foot {}
|
11
11
|
|
12
12
|
title: 404 - Page not found
|
13
13
|
keywords: ""
|
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Milk::Page
|
2
2
|
components:
|
3
|
-
- !ruby/object:Head {}
|
3
|
+
- !ruby/object:Milk::Components::Head {}
|
4
4
|
|
5
|
-
- !ruby/object:Body
|
5
|
+
- !ruby/object:Milk::Components::Body
|
6
6
|
markdown: |-
|
7
7
|
# Products
|
8
8
|
|
9
9
|
Description of products page
|
10
|
-
- !ruby/object:Foot {}
|
10
|
+
- !ruby/object:Milk::Components::Foot {}
|
11
11
|
|
12
12
|
title: Products
|
13
13
|
keywords: ""
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Milk::Components
|
2
|
+
class Button < Milk::Component
|
3
|
+
local_properties :href, :icon, :title, :description
|
4
|
+
|
5
|
+
page_chooser :href, "Link target"
|
6
|
+
text_field :title, "Label text"
|
7
|
+
text_field :description, "Tooltip"
|
8
|
+
|
9
|
+
def name
|
10
|
+
@title + " button"
|
11
|
+
end
|
12
|
+
|
13
|
+
# highlight if current page shares base folder with target of link
|
14
|
+
def css_class
|
15
|
+
(page.link_to.split('/')[1] == @href.split('/')[1] || page.link_to?(@href)) && "active"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Milk::Fields
|
2
2
|
class PageChooser < Milk::Field
|
3
3
|
@@pages = []
|
4
|
-
Dir.glob(Milk::
|
4
|
+
Dir.glob(Milk::DATA_DIR + "/pages/*.yaml").each do |page|
|
5
5
|
pagename = File.basename(page, '.yaml').rpartition('/').last.gsub('.','/')
|
6
6
|
@@pages << {
|
7
7
|
file: page,
|
File without changes
|
@@ -0,0 +1,121 @@
|
|
1
|
+
function on_click_sprite(e)
|
2
|
+
{
|
3
|
+
// Look up some useful variables
|
4
|
+
var current = e.currentTarget;
|
5
|
+
var sprite_select = $(current.parentNode);
|
6
|
+
var peers = $(".sprite-option", sprite_select);
|
7
|
+
var hidden_input = $('input', sprite_select)[0];
|
8
|
+
var inner_span = $('span', current)[0];
|
9
|
+
|
10
|
+
// Set the value on the hidden input
|
11
|
+
hidden_input.value = inner_span.title;
|
12
|
+
|
13
|
+
// Move the highlight
|
14
|
+
peers.removeClass('ui-state-highlight');
|
15
|
+
$(current).addClass('ui-state-highlight');
|
16
|
+
update_preview(50);
|
17
|
+
}
|
18
|
+
|
19
|
+
function jsonify(form)
|
20
|
+
{
|
21
|
+
var data = {}
|
22
|
+
$("input, textarea, select", form).each(function (i, field){
|
23
|
+
var parts = field.name.split(':');
|
24
|
+
var root = data;
|
25
|
+
var part = parts[0];
|
26
|
+
var numeric_regexp = /[0-9]+/;
|
27
|
+
for(i=0;i<parts.length-1;i++)
|
28
|
+
{
|
29
|
+
if (!root[part])
|
30
|
+
{
|
31
|
+
if (numeric_regexp.test(part))
|
32
|
+
root[part]={};
|
33
|
+
else
|
34
|
+
root[part]=[];
|
35
|
+
}
|
36
|
+
root = root[part];
|
37
|
+
part = parts[i + 1];
|
38
|
+
}
|
39
|
+
value = field.value
|
40
|
+
if (field.type == 'checkbox')
|
41
|
+
{
|
42
|
+
value = field.checked;
|
43
|
+
}
|
44
|
+
root[part] = value;
|
45
|
+
});
|
46
|
+
console.log(data);
|
47
|
+
return $.toJSON(data);
|
48
|
+
}
|
49
|
+
|
50
|
+
function do_update_preview()
|
51
|
+
{
|
52
|
+
var preview = $("#preview");
|
53
|
+
$("body").addClass("busy")
|
54
|
+
$.ajax({
|
55
|
+
type: "POST",
|
56
|
+
url: $("form")[0].action,
|
57
|
+
contentType: "application/json",
|
58
|
+
data: jsonify($("form")[0]),
|
59
|
+
success: function(msg){
|
60
|
+
preview.html(msg);
|
61
|
+
$("body").removeClass("busy")
|
62
|
+
}
|
63
|
+
});
|
64
|
+
}
|
65
|
+
|
66
|
+
function update_preview(timeout)
|
67
|
+
{
|
68
|
+
clearTimeout(window.preview_timeout);
|
69
|
+
window.preview_timeout = setTimeout(do_update_preview, timeout);
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
$(function() {
|
74
|
+
$("#left").resizable({handles: "e", resize: function(event, ui) {
|
75
|
+
$("#divider").css("left", ui.size.width);
|
76
|
+
$("#preview").css("left", ui.size.width+5);
|
77
|
+
}});
|
78
|
+
$(".sub-fields").accordion({
|
79
|
+
collapsible: true,
|
80
|
+
autoHeight: false,
|
81
|
+
active: false
|
82
|
+
});
|
83
|
+
var sections = $("#fields").accordion({
|
84
|
+
autoHeight: false
|
85
|
+
});
|
86
|
+
|
87
|
+
$(".sprite-option").click(on_click_sprite);
|
88
|
+
$(".toolitem, .sprite-option")
|
89
|
+
.addClass("ui-state-default ui-corner-all")
|
90
|
+
.hover(
|
91
|
+
function() { $(this).addClass('ui-state-hover'); },
|
92
|
+
function() { $(this).removeClass('ui-state-hover'); }
|
93
|
+
);
|
94
|
+
$("#fields select, #fields input, #fields textarea").change(function(){
|
95
|
+
update_preview(100);
|
96
|
+
});
|
97
|
+
$("#fields select, #fields input, #fields textarea").keyup(function(){
|
98
|
+
update_preview(1000);
|
99
|
+
});
|
100
|
+
$("#save_button").click(function(){
|
101
|
+
$.ajax({
|
102
|
+
type: "PUT",
|
103
|
+
url: $("form")[0].action,
|
104
|
+
contentType: "application/json",
|
105
|
+
data: jsonify($("form")[0]),
|
106
|
+
success: function(msg){
|
107
|
+
window.location = $("form")[0].action.replace('https://', 'http://');
|
108
|
+
}
|
109
|
+
});
|
110
|
+
});
|
111
|
+
|
112
|
+
$("#cancel_button").click(function(){
|
113
|
+
window.location = $("form")[0].action.replace('https://', 'http://');
|
114
|
+
});
|
115
|
+
$("#logout_button").click(function(){
|
116
|
+
window.location = "/logout?dest="+$("form")[0].action.replace('https://', 'http://');
|
117
|
+
});
|
118
|
+
|
119
|
+
});
|
120
|
+
|
121
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
function form_validate(form)
|
2
|
+
{
|
3
|
+
var good = true;
|
4
|
+
$(".form_field", form).each(function(i,tr){
|
5
|
+
var field = $("input,textarea,select", tr);
|
6
|
+
console.log(field);
|
7
|
+
var required = $(tr).hasClass('required');
|
8
|
+
var message = "";
|
9
|
+
var value = field[0].value;
|
10
|
+
if (value)
|
11
|
+
{
|
12
|
+
if (field.hasClass("email_field"))
|
13
|
+
{
|
14
|
+
console.log("Validating email");
|
15
|
+
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
16
|
+
if (!filter.test(value))
|
17
|
+
{
|
18
|
+
message = "Please enter a valid email address";
|
19
|
+
}
|
20
|
+
}
|
21
|
+
else if (field.hasClass("phone_field"))
|
22
|
+
{
|
23
|
+
console.log("Validating phone");
|
24
|
+
var stripped = value.replace(/[\s()+\-]|ext\.?/gi, "");
|
25
|
+
// 10 is the minimum number of numbers required
|
26
|
+
if (!(/\d{10,}/i).test(stripped))
|
27
|
+
{
|
28
|
+
message = "Please enter a valid phone number with area code";
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
else if (required)
|
33
|
+
{
|
34
|
+
message = "This is a required field";
|
35
|
+
}
|
36
|
+
var message_area = $(".error_message", tr);
|
37
|
+
message_area.html(message);
|
38
|
+
if (message === "")
|
39
|
+
{
|
40
|
+
message_area.hide();
|
41
|
+
}
|
42
|
+
else
|
43
|
+
{
|
44
|
+
good = false;
|
45
|
+
message_area.show();
|
46
|
+
}
|
47
|
+
});
|
48
|
+
console.log(good);
|
49
|
+
return false;
|
50
|
+
|
51
|
+
}
|