koda 0.0.8

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 (161) hide show
  1. data/lib/helpers/app_helper.rb +40 -0
  2. data/lib/helpers/koda_helper.rb +105 -0
  3. data/lib/helpers/view_helper.rb +146 -0
  4. data/lib/koda.rb +123 -0
  5. data/lib/models/hash.rb +29 -0
  6. data/lib/models/mongo_collection.rb +144 -0
  7. data/lib/models/mongo_config.rb +22 -0
  8. data/lib/models/mongo_database.rb +136 -0
  9. data/lib/models/mongo_document.rb +124 -0
  10. data/lib/models/mongo_grid.rb +85 -0
  11. data/lib/models/mongo_media.rb +55 -0
  12. data/lib/models/user_access_provider.rb +135 -0
  13. data/lib/models/user_context.rb +19 -0
  14. data/lib/routes/koda_api.rb +392 -0
  15. data/lib/routes/koda_site.rb +57 -0
  16. data/lib/views/console.erb +139 -0
  17. data/lib/views/explorer.erb +119 -0
  18. data/lib/views/login.erb +77 -0
  19. data/lib/views/not_allowed.erb +75 -0
  20. data/public/koda/Help/DataTypes.txt +82 -0
  21. data/public/koda/Help/KodaType_Template.js +48 -0
  22. data/public/koda/apple-touch-icon-114x114-precomposed.png +0 -0
  23. data/public/koda/apple-touch-icon-144x144-precomposed.png +0 -0
  24. data/public/koda/apple-touch-icon-57x57-precomposed.png +0 -0
  25. data/public/koda/apple-touch-icon-72x72-precomposed.png +0 -0
  26. data/public/koda/apple-touch-icon-precomposed.png +0 -0
  27. data/public/koda/apple-touch-icon.png +0 -0
  28. data/public/koda/css/bootstrap-responsive.css +1058 -0
  29. data/public/koda/css/bootstrap.css +5774 -0
  30. data/public/koda/css/main.css +288 -0
  31. data/public/koda/favicon.ico +0 -0
  32. data/public/koda/fonts/angelina-webfont.eot +0 -0
  33. data/public/koda/fonts/angelina-webfont.svg +228 -0
  34. data/public/koda/fonts/angelina-webfont.ttf +0 -0
  35. data/public/koda/fonts/angelina-webfont.woff +0 -0
  36. data/public/koda/fonts/coolvetica_rg-webfont.eot +0 -0
  37. data/public/koda/fonts/coolvetica_rg-webfont.svg +232 -0
  38. data/public/koda/fonts/coolvetica_rg-webfont.ttf +0 -0
  39. data/public/koda/fonts/coolvetica_rg-webfont.woff +0 -0
  40. data/public/koda/fonts/ladyic__-webfont.eot +0 -0
  41. data/public/koda/fonts/ladyic__-webfont.svg +257 -0
  42. data/public/koda/fonts/ladyic__-webfont.ttf +0 -0
  43. data/public/koda/fonts/ladyic__-webfont.woff +0 -0
  44. data/public/koda/images/ajax-loader.gif +0 -0
  45. data/public/koda/images/back.png +0 -0
  46. data/public/koda/images/bg-table-thead.png +0 -0
  47. data/public/koda/images/big_folder.png +0 -0
  48. data/public/koda/images/box_file.png +0 -0
  49. data/public/koda/images/car_add.png +0 -0
  50. data/public/koda/images/compress.png +0 -0
  51. data/public/koda/images/database_table.png +0 -0
  52. data/public/koda/images/feed_add.png +0 -0
  53. data/public/koda/images/feed_link.png +0 -0
  54. data/public/koda/images/file.png +0 -0
  55. data/public/koda/images/folder.png +0 -0
  56. data/public/koda/images/folder_image.png +0 -0
  57. data/public/koda/images/glyphicons-halflings-white.png +0 -0
  58. data/public/koda/images/glyphicons-halflings.png +0 -0
  59. data/public/koda/images/group_add.png +0 -0
  60. data/public/koda/images/group_key.png +0 -0
  61. data/public/koda/images/image_add.png +0 -0
  62. data/public/koda/images/layout_add.png +0 -0
  63. data/public/koda/images/package.png +0 -0
  64. data/public/koda/images/page_white_edit.png +0 -0
  65. data/public/koda/images/page_white_text.png +0 -0
  66. data/public/koda/images/photo_add.png +0 -0
  67. data/public/koda/images/toggle-collapse-dark.png +0 -0
  68. data/public/koda/images/toggle-collapse-light.png +0 -0
  69. data/public/koda/images/toggle-expand-dark.png +0 -0
  70. data/public/koda/images/toggle-expand-light.png +0 -0
  71. data/public/koda/images/twitter.png +0 -0
  72. data/public/koda/koda-editors/KodaEditor.js +843 -0
  73. data/public/koda/koda-editors/collection-editor.html +56 -0
  74. data/public/koda/koda-editors/generic-editor.css +112 -0
  75. data/public/koda/koda-editors/generic-editor.html +74 -0
  76. data/public/koda/koda-editors/koda-editor.css +72 -0
  77. data/public/koda/koda-editors/twitterfeed-editor.html +90 -0
  78. data/public/koda/koda-types/_builtin_registration.json +62 -0
  79. data/public/koda/koda-types/koda-access.json +49 -0
  80. data/public/koda/koda-types/koda-collection.json +12 -0
  81. data/public/koda/koda-types/koda-generictext.json +50 -0
  82. data/public/koda/koda-types/koda-media.json +58 -0
  83. data/public/koda/koda-types/koda-twitterfeed.json +79 -0
  84. data/public/koda/koda-types/koda-user.json +71 -0
  85. data/public/koda/nicEditorIcons.gif +0 -0
  86. data/public/koda/scripts/Koda.js +1200 -0
  87. data/public/koda/scripts/lib/DOMAssistant.js +4 -0
  88. data/public/koda/scripts/lib/modernizr.js +4 -0
  89. data/public/koda/scripts/lib/respond.js +2 -0
  90. data/public/koda/scripts/lib/selectivizr.js +5 -0
  91. data/public/koda/scripts/plugins/bootstrap.js +2027 -0
  92. data/public/koda/scripts/plugins/box.js +8 -0
  93. data/public/koda/scripts/plugins/fancybox/blank.gif +0 -0
  94. data/public/koda/scripts/plugins/fancybox/fancy_close.png +0 -0
  95. data/public/koda/scripts/plugins/fancybox/fancy_loading.png +0 -0
  96. data/public/koda/scripts/plugins/fancybox/fancy_nav_left.png +0 -0
  97. data/public/koda/scripts/plugins/fancybox/fancy_nav_right.png +0 -0
  98. data/public/koda/scripts/plugins/fancybox/fancy_shadow_e.png +0 -0
  99. data/public/koda/scripts/plugins/fancybox/fancy_shadow_n.png +0 -0
  100. data/public/koda/scripts/plugins/fancybox/fancy_shadow_ne.png +0 -0
  101. data/public/koda/scripts/plugins/fancybox/fancy_shadow_nw.png +0 -0
  102. data/public/koda/scripts/plugins/fancybox/fancy_shadow_s.png +0 -0
  103. data/public/koda/scripts/plugins/fancybox/fancy_shadow_se.png +0 -0
  104. data/public/koda/scripts/plugins/fancybox/fancy_shadow_sw.png +0 -0
  105. data/public/koda/scripts/plugins/fancybox/fancy_shadow_w.png +0 -0
  106. data/public/koda/scripts/plugins/fancybox/fancy_title_left.png +0 -0
  107. data/public/koda/scripts/plugins/fancybox/fancy_title_main.png +0 -0
  108. data/public/koda/scripts/plugins/fancybox/fancy_title_over.png +0 -0
  109. data/public/koda/scripts/plugins/fancybox/fancy_title_right.png +0 -0
  110. data/public/koda/scripts/plugins/fancybox/fancybox-x.png +0 -0
  111. data/public/koda/scripts/plugins/fancybox/fancybox-y.png +0 -0
  112. data/public/koda/scripts/plugins/fancybox/fancybox.png +0 -0
  113. data/public/koda/scripts/plugins/fancybox/jquery.easing-1.3.pack.js +72 -0
  114. data/public/koda/scripts/plugins/fancybox/jquery.fancybox-1.3.4.css +359 -0
  115. data/public/koda/scripts/plugins/fancybox/jquery.fancybox-1.3.4.js +1155 -0
  116. data/public/koda/scripts/plugins/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
  117. data/public/koda/scripts/plugins/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
  118. data/public/koda/scripts/plugins/fileuploader.js +1527 -0
  119. data/public/koda/scripts/plugins/jquery-class.js +7 -0
  120. data/public/koda/scripts/plugins/jquery.contextmenu/images/cut.png +0 -0
  121. data/public/koda/scripts/plugins/jquery.contextmenu/images/door.png +0 -0
  122. data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_copy.png +0 -0
  123. data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_delete.png +0 -0
  124. data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_edit.png +0 -0
  125. data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_paste.png +0 -0
  126. data/public/koda/scripts/plugins/jquery.contextmenu/jquery.contextMenu.css +63 -0
  127. data/public/koda/scripts/plugins/jquery.contextmenu/jquery.contextMenu.js +211 -0
  128. data/public/koda/scripts/plugins/jquery.js +2 -0
  129. data/public/koda/scripts/plugins/json2.js +277 -0
  130. data/public/koda/scripts/plugins/modernizr.js +2 -0
  131. data/public/koda/scripts/plugins/nicEdit.js +183 -0
  132. data/public/koda/scripts/plugins/qunit.js +1448 -0
  133. data/public/koda/scripts/plugins/spin.js +2 -0
  134. data/public/koda/scripts/plugins/uploader/README.md +77 -0
  135. data/public/koda/scripts/plugins/uploader/README.txt +89 -0
  136. data/public/koda/scripts/plugins/uploader/example/application.js +20 -0
  137. data/public/koda/scripts/plugins/uploader/example/index.html +109 -0
  138. data/public/koda/scripts/plugins/uploader/example/style.css +22 -0
  139. data/public/koda/scripts/plugins/uploader/example/upload.php +313 -0
  140. data/public/koda/scripts/plugins/uploader/jquery.fileupload-ui.css +100 -0
  141. data/public/koda/scripts/plugins/uploader/jquery.fileupload-ui.js +642 -0
  142. data/public/koda/scripts/plugins/uploader/jquery.fileupload.js +711 -0
  143. data/public/koda/scripts/plugins/uploader/jquery.iframe-transport.js +133 -0
  144. data/public/koda/scripts/plugins/uploader/pbar-ani.gif +0 -0
  145. data/public/koda/scripts/plugins/uploader/tests/index.html +115 -0
  146. data/public/koda/scripts/plugins/uploader/tests/tests.js +1008 -0
  147. data/public/koda/scripts/require.js +32 -0
  148. data/public/koda/scripts/specs.js +12 -0
  149. data/public/koda/scripts/specs/cd-command-spec.js +51 -0
  150. data/public/koda/scripts/specs/controller-spec.js +95 -0
  151. data/public/koda/scripts/specs/doubles/mock-command.js +21 -0
  152. data/public/koda/scripts/specs/doubles/mock-jamservice.js +33 -0
  153. data/public/koda/scripts/specs/doubles/mock-prompt.js +30 -0
  154. data/public/koda/scripts/specs/doubles/uiobject-double.js +15 -0
  155. data/public/koda/scripts/specs/edit-command-spec.js +76 -0
  156. data/public/koda/scripts/specs/ls-command-spec.js +61 -0
  157. data/public/koda/scripts/specs/mkdir-command-spec.js +40 -0
  158. data/public/koda/scripts/specs/peek-command-spec.js +24 -0
  159. data/public/koda/scripts/specs/remove-command-spec.js +37 -0
  160. data/public/koda/scripts/specs/service-spec.js +85 -0
  161. metadata +402 -0
@@ -0,0 +1,49 @@
1
+ {
2
+ "title" : "User Access Editor",
3
+ "fields" : [
4
+ {
5
+ "id" : "_koda_type",
6
+ "defaultValue" : "/koda/koda-types/koda-access.json"
7
+ },
8
+ {
9
+ "id" : "_koda_hidden_file",
10
+ "defaultValue" : "true"
11
+ },
12
+ {
13
+ "id" : "_koda_editor",
14
+ "defaultValue" : "/koda/koda-editors/generic-editor.html"
15
+ },
16
+ {
17
+ "id" : "datecreated",
18
+ "defaultValue" : "<%=timestamp%>"
19
+ },
20
+ {
21
+ "id" : "alias",
22
+ "defaultValue" : "access-control"
23
+ },
24
+ {
25
+ "id" : "read_users",
26
+ "title" : "Users with read access",
27
+ "description" : "Comma separated users that are allowed to view this collection (* for all, - for admin only)",
28
+ "control" : "input-text",
29
+ "properties" : "required",
30
+ "defaultValue" : "*"
31
+ },
32
+ {
33
+ "id" : "write_users",
34
+ "title" : "Users with write access",
35
+ "description" : "Comma separated users that are allowed to write to this collection (* for all, - for admin only)",
36
+ "control" : "input-text",
37
+ "properties" : "required",
38
+ "defaultValue" : "*"
39
+ },
40
+ {
41
+ "id" : "modify_users",
42
+ "title" : "Users with modify access",
43
+ "description" : "Comma separated users that are allowed to write to this collection (* for all, - for admin only)",
44
+ "control" : "input-text",
45
+ "properties" : "required",
46
+ "defaultValue" : "*"
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "title" : "Folder/Collection Editor",
3
+ "fields" : [
4
+ {
5
+ "id" : "name",
6
+ "title" : "Collection Name",
7
+ "description" : "Name for your collection",
8
+ "control" : "input-text",
9
+ "defaultValue" : ""
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "title" : "Generic Text Editor",
3
+ "fields" : [
4
+ {
5
+ "id" : "_koda_type",
6
+ "defaultValue" : "/koda/koda-types/koda-generictext.json"
7
+ },
8
+ {
9
+ "id" : "_koda_editor",
10
+ "defaultValue" : "/koda/koda-editors/generic-editor.html"
11
+ },
12
+ {
13
+ "id" : "_koda_indexes",
14
+ "defaultValue" : "name,tags"
15
+ },
16
+ {
17
+ "id" : "datecreated",
18
+ "defaultValue" : "<%=timestamp%>"
19
+ },
20
+ {
21
+ "id" : "name",
22
+ "title" : "Name",
23
+ "description" : "The name of the content",
24
+ "control" : "input-text",
25
+ "defaultValue" : "",
26
+ "properties" : "required"
27
+ },
28
+ {
29
+ "id" : "alias",
30
+ "title" : "Alias",
31
+ "description" : "This will be generated from the title",
32
+ "control" : "input-readonly",
33
+ "defaultValue" : ""
34
+ },
35
+ {
36
+ "id" : "content",
37
+ "title" : "Content",
38
+ "description" : "The contents",
39
+ "control" : "richtext",
40
+ "defaultValue" : ""
41
+ },
42
+ {
43
+ "id" : "tags",
44
+ "title" : "Tags",
45
+ "description" : "Comma separated",
46
+ "control" : "input-text",
47
+ "defaultValue" : ""
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "title" : "Koda Media Editor",
3
+ "fields" : [
4
+ {
5
+ "id" : "_koda_type",
6
+ "defaultValue" : "/koda/koda-types/koda-media.json"
7
+ },
8
+ {
9
+ "id" : "_koda_editor",
10
+ "defaultValue" : "/koda/koda-editors/generic-editor.html"
11
+ },
12
+ {
13
+ "id" : "_koda_indexes",
14
+ "defaultValue" : "name,tags"
15
+ },
16
+ {
17
+ "id" : "datecreated",
18
+ "defaultValue" : "<%=timestamp%>"
19
+ },
20
+ {
21
+ "id" : "name",
22
+ "title" : "Name",
23
+ "description" : "The name of the image",
24
+ "control" : "input-text",
25
+ "properties" : "required",
26
+ "defaultValue" : ""
27
+ },
28
+ {
29
+ "id" : "alias",
30
+ "title" : "Alias",
31
+ "description" : "This will be generated from the title",
32
+ "control" : "input-readonly",
33
+ "defaultValue" : ""
34
+ },
35
+ {
36
+ "id" : "mime_type",
37
+ "title" : "Mime Type",
38
+ "description" : "Pick the type of file to upload",
39
+ "control" : "collection",
40
+ "values" : "application/pdf,application/zip, application/gzip,image/gif,image/jpeg,image/png,audio/mpeg,audio/ogg,video/mpeg,video/mp4,video/x-flv",
41
+ "defaultValue" : "image/png"
42
+ },
43
+ {
44
+ "id" : "media_file",
45
+ "title" : "File to upload",
46
+ "description" : "The media file to upload",
47
+ "control" : "mediaupload",
48
+ "defaultValue" : ""
49
+ },
50
+ {
51
+ "id" : "tags",
52
+ "title" : "Tags",
53
+ "description" : "Comma separated",
54
+ "control" : "input-text",
55
+ "defaultValue" : ""
56
+ }
57
+ ]
58
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "title" : "Koda Twitter Feed Editor",
3
+ "fields" : [
4
+ {
5
+ "id" : "_koda_type",
6
+ "defaultValue" : "/koda/koda-types/koda-twitterfeed.json"
7
+ },
8
+ {
9
+ "id" : "_koda_editor",
10
+ "defaultValue" : "/koda/koda-editors/twitterfeed-editor.html"
11
+ },
12
+ {
13
+ "id" : "_koda_indexes",
14
+ "defaultValue" : "name,tags"
15
+ },
16
+ {
17
+ "id" : "datecreated",
18
+ "defaultValue" : "<%=timestamp%>"
19
+ },
20
+ {
21
+ "id" : "showuserfeed",
22
+ "title" : "Show a user feed?",
23
+ "description" : "Do you want to show a user timeline?",
24
+ "control" : "truefalse",
25
+ "defaultValue" : false
26
+ },
27
+ {
28
+ "id" : "name",
29
+ "title" : "Twitter handle",
30
+ "description" : "The screen name of the twitter feed",
31
+ "control" : "input-text",
32
+ "defaultValue" : ""
33
+ },
34
+ {
35
+ "id" : "alias",
36
+ "title" : "Alias",
37
+ "description" : "This will be generated from the title",
38
+ "control" : "input-readonly",
39
+ "defaultValue" : ""
40
+ },
41
+ {
42
+ "id" : "user_count",
43
+ "title" : "How many?",
44
+ "description" : "The amount of latest messages to include (1-10)",
45
+ "control" : "input-range",
46
+ "defaultValue" : "",
47
+ "properties" : "min='1' max='10'"
48
+ },
49
+ {
50
+ "id" : "showqueriedfeed",
51
+ "title" : "Show a custom query?",
52
+ "description" : "Do you want to show a custom feed based on a query?",
53
+ "control" : "truefalse",
54
+ "defaultValue" : false
55
+ },
56
+ {
57
+ "id" : "query",
58
+ "title" : "Custom query",
59
+ "description" : "The query or tag to search",
60
+ "control" : "input-text",
61
+ "defaultValue" : ""
62
+ },
63
+ {
64
+ "id" : "query_count",
65
+ "title" : "How many?",
66
+ "description" : "The amount of latest messages to include (1-10)",
67
+ "control" : "input-range",
68
+ "defaultValue" : "",
69
+ "properties" : "min='1' max='10'"
70
+ },
71
+ {
72
+ "id" : "tags",
73
+ "title" : "Tags",
74
+ "description" : "Comma separated",
75
+ "control" : "input-text",
76
+ "defaultValue" : ""
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "title" : "Koda User Editor",
3
+ "fields" : [
4
+ {
5
+ "id" : "_koda_type",
6
+ "defaultValue" : "/koda/koda-types/koda-user.json"
7
+ },
8
+ {
9
+ "id" : "_koda_editor",
10
+ "defaultValue" : "/koda/koda-editors/generic-editor.html"
11
+ },
12
+ {
13
+ "id" : "_koda_indexes",
14
+ "defaultValue" : "name,email"
15
+ },
16
+ {
17
+ "id" : "datecreated",
18
+ "defaultValue" : "<%=timestamp%>"
19
+ },
20
+ {
21
+ "id" : "googleid",
22
+ "defaultValue" : ""
23
+ },
24
+ {
25
+ "id" : "name",
26
+ "title" : "Username",
27
+ "description" : "Prefered Username",
28
+ "control" : "input-text",
29
+ "properties" : "required placeholder='joeblogs'",
30
+ "defaultValue" : ""
31
+ },
32
+ {
33
+ "id" : "alias",
34
+ "title" : "Alias",
35
+ "description" : "This will be generated from the username",
36
+ "control" : "input-readonly",
37
+ "defaultValue" : ""
38
+ },
39
+ {
40
+ "id" : "email",
41
+ "title" : "Email address",
42
+ "description" : "email address of user",
43
+ "control" : "input-email",
44
+ "properties" : "required placeholder='joe@blogs.com'",
45
+ "defaultValue" : ""
46
+ },
47
+ {
48
+ "id" : "isallowed",
49
+ "title" : "Is Allowed",
50
+ "description" : "Is this user allowed in the backoffice?",
51
+ "control" : "truefalse",
52
+ "properties" : "required",
53
+ "defaultValue" : false
54
+ },
55
+ {
56
+ "id" : "isadmin",
57
+ "title" : "Is Admin",
58
+ "description" : "Access to console and can do anything.",
59
+ "control" : "truefalse",
60
+ "properties" : "required",
61
+ "defaultValue" : false
62
+ },
63
+ {
64
+ "id" : "tags",
65
+ "title" : "Tags",
66
+ "description" : "Comma separated",
67
+ "control" : "input-text",
68
+ "defaultValue" : ""
69
+ }
70
+ ]
71
+ }
@@ -0,0 +1,1200 @@
1
+ $.fn.spin = function(opts) {
2
+ this.each(function() {
3
+ var $this = $(this),
4
+ data = $this.data();
5
+
6
+ if (data.spinner) {
7
+ data.spinner.stop();
8
+ delete data.spinner;
9
+ }
10
+ if (opts !== false) {
11
+ data.spinner = new Spinner($.extend({color: $this.css('color')}, opts)).spin(this);
12
+ }
13
+ });
14
+ return this;
15
+ };
16
+
17
+ String.prototype.parseDate = function() {
18
+ var date = new Date(Date.parse(this));
19
+ var curr_date = date.getDate();
20
+ var curr_month = date.getMonth() + 1; //Months are zero based
21
+ var curr_year = date.getFullYear();
22
+ return curr_date + "-" + curr_month + "-" + curr_year;
23
+ }
24
+
25
+ Date.prototype.parseDate = function() {
26
+ var curr_date = this.getDate();
27
+ var curr_month = this.getMonth() + 1; //Months are zero based
28
+ var curr_year = this.getFullYear();
29
+ return curr_date + "-" + curr_month + "-" + curr_year;
30
+ }
31
+
32
+ var spinnerOpts = {
33
+ lines: 9, // The number of lines to draw
34
+ length: 0, // The length of each line
35
+ width: 5, // The line thickness
36
+ radius: 10, // The radius of the inner circle
37
+ corners: 0.9, // Corner roundness (0..1)
38
+ rotate: 0, // The rotation offset
39
+ color: '#000', // #rgb or #rrggbb
40
+ speed: 1.2, // Rounds per second
41
+ trail: 30, // Afterglow percentage
42
+ shadow: false, // Whether to render a shadow
43
+ hwaccel: false, // Whether to use hardware acceleration
44
+ className: 'spinner', // The CSS class to assign to the spinner
45
+ zIndex: 2e9, // The z-index (defaults to 2000000000)
46
+ top: 'auto', // Top position relative to parent in px
47
+ left: 'auto' // Left position relative to parent in px
48
+ };
49
+
50
+ /*
51
+ ----------------------------------------------------------
52
+ Service
53
+ ----------------------------------------------------------
54
+ */
55
+
56
+ $.Class.extend("RestService",
57
+ {},
58
+ {
59
+ init : function() { },
60
+
61
+ getError : function(error) {
62
+ if(error.status == 405){
63
+ return 'You were not allowed to perform this action!'
64
+ }
65
+
66
+ return error.statusText;
67
+ },
68
+
69
+ get: function(path, callback) {
70
+
71
+ var location = path != undefined ? path : StringUtil.empty;
72
+ self = this;
73
+
74
+ jQuery.ajax({
75
+ type: "GET",
76
+ url: Session.kodaUrl+"/"+location + "?include=false&" + new Date().getTime(),
77
+ dataType: "json",
78
+ success: function(results){
79
+ callback(results);
80
+ },
81
+ error: function(XMLHttpRequest, textStatus, errorThrown){
82
+ callback({error: self.getError(XMLHttpRequest), code: XMLHttpRequest.status});
83
+ }
84
+ });
85
+
86
+ },
87
+
88
+ getExternal: function(path, callback) {
89
+ self = this;
90
+
91
+ jQuery.ajax({
92
+ type: "GET",
93
+ url: path + "?" + new Date().getTime(),
94
+ dataType: "json",
95
+ success: function(results){
96
+ callback(results);
97
+ },
98
+ error: function(XMLHttpRequest, textStatus, errorThrown){
99
+ callback({error: self.getError(XMLHttpRequest), code: XMLHttpRequest.status});
100
+ }
101
+ });
102
+
103
+ },
104
+
105
+ delete: function(path, callback) {
106
+
107
+ var location = path != undefined ? path : StringUtil.empty;
108
+ self = this;
109
+
110
+ jQuery.ajax({
111
+ type: "DELETE",
112
+ url: Session.kodaUrl+"/"+location,
113
+ dataType: "json",
114
+ success: function(result){
115
+ callback("OK");
116
+ },
117
+ error: function(XMLHttpRequest){
118
+ callback({error: self.getError(XMLHttpRequest), code: XMLHttpRequest.status});
119
+ }
120
+ });
121
+
122
+ },
123
+
124
+ put: function(path, resource, callback) {
125
+
126
+ var location = path != undefined ? path : StringUtil.empty;
127
+ self = this;
128
+
129
+ jQuery.ajax({
130
+ type: "PUT",
131
+ url: Session.kodaUrl+"/"+location,
132
+ data: resource,
133
+ dataType: "json",
134
+ success: function(result){
135
+ callback("OK");
136
+ },
137
+ error: function(XMLHttpRequest){
138
+ if(XMLHttpRequest.status == "201" || XMLHttpRequest.status == "200") {
139
+ callback("OK")
140
+ }
141
+ else {
142
+ callback({error: self.getError(XMLHttpRequest), code: XMLHttpRequest.status});
143
+ }
144
+ }
145
+ });
146
+
147
+ },
148
+
149
+
150
+ post: function(path, resource, callback) {
151
+
152
+ var location = path != undefined ? path : StringUtil.empty;
153
+ self = this;
154
+
155
+ jQuery.ajax({
156
+ type: "POST",
157
+ url: Session.kodaUrl+"/"+location,
158
+ data: resource,
159
+ dataType: "json",
160
+ success: function(result){
161
+ callback("OK");
162
+ },
163
+ error: function(XMLHttpRequest){
164
+
165
+ if(XMLHttpRequest.status == "201" || XMLHttpRequest.status == "200") {
166
+ callback("OK")
167
+ }
168
+ else {
169
+ callback({error: self.getError(XMLHttpRequest), code: XMLHttpRequest.status});
170
+ }
171
+ }
172
+ });
173
+
174
+ }
175
+
176
+ }
177
+ );
178
+
179
+ /*
180
+ ----------------------------------------------------------
181
+ Utils
182
+ ----------------------------------------------------------
183
+ */
184
+
185
+ $.Class.extend("QueryString",
186
+ {},
187
+ {
188
+ getItem : function(key) {
189
+
190
+ key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
191
+ var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
192
+ var qs = regex.exec(window.location.href);
193
+
194
+ if(qs != undefined && qs.length > 0)
195
+ return qs[1];
196
+
197
+ return "";
198
+
199
+ }
200
+ });
201
+
202
+ $.Class.extend("StringUtil", {
203
+
204
+ format: function() {
205
+
206
+ var s = arguments[0];
207
+ for (var i = 0; i < arguments.length - 1; i++) {
208
+ var reg = new RegExp("\\{" + i + "\\}", "gm");
209
+ s = s.replace(reg, arguments[i + 1]);
210
+ }
211
+
212
+ return s;
213
+
214
+ },
215
+
216
+ empty: ""
217
+
218
+ }, {});
219
+
220
+ /*
221
+ ----------------------------------------------------------
222
+ Presenters
223
+ ----------------------------------------------------------
224
+ */
225
+
226
+ $.Class.extend("ConsolePresenter",
227
+ { uiObject: {}, controller: {}, isCtrl: false },
228
+ {
229
+ init : function(controller){
230
+
231
+ this.Class.controller = controller;
232
+ this.Class.uiObject = $('#console');
233
+ },
234
+
235
+ attach: function() {
236
+
237
+ this.Class.uiObject.delegate('.active textarea', 'keyup', this.editorKeyup);
238
+ this.Class.uiObject.delegate('.active textarea', 'keydown', this.editorKeydown);
239
+ },
240
+
241
+ editorKeyup: function(e) {
242
+ if(e.which == 17) ConsolePresenter.isCtrl=false; // ctrl
243
+ },
244
+
245
+ editorKeydown: function(e) {
246
+ if (e.which == 9) { // tab
247
+ var self = ConsolePresenter;
248
+ e.preventDefault();
249
+ var val = Prompt.getInput();
250
+ var autoCompleted = self.controller.autocomplete(val);
251
+ Prompt.writeToInput(autoCompleted);
252
+
253
+ } else if(!Prompt.multiline && e.which == 13){ //enter
254
+ e.preventDefault();
255
+ val = Prompt.getInput();
256
+
257
+ if(Prompt.promptInputOverride && Prompt.promptOverrideDelegate) {
258
+
259
+ Prompt.promptOverrideDelegate(val);
260
+
261
+ } else {
262
+
263
+ ConsolePresenter.controller.processLine(val, function(output) {
264
+ Prompt.writeToOutput(output);
265
+ });
266
+
267
+ }
268
+ } else if(Prompt.multiline && e.which == 17) { // ctrl
269
+ ConsolePresenter.isCtrl=true
270
+ } else if(Prompt.multiline && e.which == 67 && ConsolePresenter.isCtrl == true) { // C
271
+
272
+ e.preventDefault();
273
+ val = Prompt.getInput();
274
+
275
+ if(Prompt.promptInputOverride && Prompt.promptOverrideDelegate) {
276
+
277
+ Prompt.promptOverrideDelegate(val);
278
+
279
+ } else {
280
+
281
+ ConsolePresenter.controller.processLine(val, function(output) {
282
+ Prompt.writeToOutput(output);
283
+ });
284
+
285
+ }
286
+
287
+ }
288
+ }
289
+
290
+ }
291
+
292
+ );
293
+
294
+ $.Class.extend("ExplorerPresenter",
295
+ { panel: {}, kodaTypes:{}, controller: {}, isCtrl: false },
296
+ {
297
+ init : function(controller, kodaTypes){
298
+
299
+ this.Class.controller = controller;
300
+ this.Class.panel = $('#explorer-panel');
301
+ this.Class.panel.delegate('li', 'click', this.selectItem);
302
+ this.Class.kodaTypes = kodaTypes;
303
+ },
304
+
305
+ toggleRoot: function(root) {
306
+ if(root){
307
+ $('.allowed-in-root').show();
308
+ $('.allowed-in-collection').hide();
309
+ } else {
310
+ $('.allowed-in-root').hide();
311
+ $('.allowed-in-collection').show();
312
+ }
313
+
314
+ // rebind events
315
+ $('.kodaType a.new').unbind('click');
316
+ $('.kodaType a.new').click(this.new);
317
+ },
318
+
319
+ showInfo : function(message){
320
+ $('#status-text').text(message);
321
+ $('#status-text').addClass('alert alert-warning');
322
+ $('#status-text').show().fadeOut(7000);
323
+ },
324
+
325
+ attach: function() {
326
+
327
+ var self = this;
328
+
329
+ $.each(this.Class.kodaTypes, function(i, group){
330
+
331
+ if(group.admin_users && !Window.current_user.isadmin) {
332
+ return;
333
+ }
334
+ var header = '<li class="nav-header">'+group.title+'</li>'
335
+ $(header).appendTo('ul.nav-list')
336
+ $.each(group.types, function(i, kodaType){
337
+ var li = $('<li class="kodaType allowed-in-'+kodaType.allowedin+'"></li>');
338
+ var a_img = '<img src="'+kodaType.icon+'" class="img-icon" /><a class="new" data-editor-url="'+kodaType.editor+'" data-type-url="'+kodaType.type+'" title="'+kodaType.description+'">'+kodaType.title+'</a>'
339
+ $(a_img).appendTo(li);
340
+ $(li).appendTo('ul.nav-list');
341
+ });
342
+ });
343
+
344
+ $('.navbar-link').click(function(evt){
345
+ Session.currentFolder = 'users';
346
+ self.edit($(this).text(), 'file');
347
+ });
348
+
349
+ this.find('');
350
+ this.toggleRoot(true);
351
+ },
352
+
353
+ find: function(path) {
354
+
355
+ var self = this;
356
+ var spinner = $('#spinner').spin(spinnerOpts);
357
+ self.Class.controller.findCommand('list', function(cmd) {
358
+ cmd.execute([path], function(results){
359
+ $('#spinner').data().spinner.stop();
360
+ if(results.error){
361
+ self.showInfo(results.error);
362
+ return;
363
+ }
364
+
365
+ var list = $('<ul class="explorer-items"/>').attr('id', path);
366
+ $.each(results, function(i, item) {
367
+
368
+ if(item.id.indexOf('_koda_media') == -1 && item.id.indexOf('objectlabs-system') == -1) {
369
+
370
+ var listItem = $('<li class="well" id="'+item.id+'"/>');
371
+ var link = $('<a id="'+item.id+'"/>').text(item.name).addClass(item.type);
372
+
373
+ parsedDate = item.date_created ? item.date_created.parseDate() : '';
374
+ var date = $('<span />').text(parsedDate);
375
+
376
+ if(item.type != "collection"){
377
+ self.findType(item._koda_type, function(kodaType){
378
+ if(kodaType != undefined) {
379
+ var img = $('<img />').attr('src', kodaType.icon);
380
+ listItem.append(img);
381
+ }
382
+ });
383
+ }
384
+
385
+ listItem.append(link);
386
+ if(parsedDate != '') listItem.append(date);
387
+
388
+ listItem.appendTo(list);
389
+ $(listItem).contextMenu({
390
+ menu : 'Actions'
391
+ }, self.contextMenuClick);
392
+
393
+ }
394
+
395
+ });
396
+ list.appendTo(self.Class.panel);
397
+ });
398
+ });
399
+
400
+ },
401
+
402
+ findType : function(type, callback){
403
+
404
+ var self = this;
405
+
406
+ $.each(self.Class.kodaTypes, function(i, item){
407
+ $.each(item.types, function(i, kodaType){
408
+ if(kodaType.type == type) {
409
+ callback(kodaType);
410
+ }
411
+ })
412
+ })
413
+
414
+ return callback(undefined);
415
+
416
+ },
417
+
418
+ toTitleCase: function(str) {
419
+
420
+ return str.replace(/(?:^|\s)\w/g, function(match) {
421
+ return match.toUpperCase();
422
+ });
423
+
424
+ },
425
+
426
+ selectItem: function(e) {
427
+
428
+ var self = Window.Presenter;
429
+ var type = $(this).find('a').attr('class');
430
+ var currentItem = $(this).find('a').attr('id');
431
+
432
+ if(type == 'collection') {
433
+ $('#back-button').remove();
434
+ var backButton = $('<div id="back-button" class="well"><a>Back</a></div>').appendTo(self.Class.panel);
435
+ backButton.click(self.back);
436
+ self.Class.panel.find('ul').remove();
437
+ Session.currentFolder = currentItem;
438
+ self.find(currentItem);
439
+ self.toggleRoot(false);
440
+ } else {
441
+ self.edit(currentItem, type);
442
+ }
443
+
444
+ },
445
+
446
+ refresh : function(collection){
447
+
448
+ var self = Window.Presenter;
449
+ $('#back-button').remove();
450
+ if(collection == undefined || collection == '') {
451
+ Session.currentFolder = undefined;
452
+ self.Class.panel.find('ul').remove();
453
+ self.find('');
454
+ self.toggleRoot(true);
455
+ } else {
456
+ var backButton = $('<div id="back-button" class="well"><a>Back</a></div>').appendTo(self.Class.panel);
457
+ backButton.click(self.back);
458
+ self.Class.panel.find('ul').remove();
459
+ Session.currentFolder = collection;
460
+ self.find(collection);
461
+ self.toggleRoot(false);
462
+ }
463
+ },
464
+
465
+ back: function(e) {
466
+
467
+ $('#back-button').remove();
468
+ var self = Window.Presenter;
469
+ Session.currentFolder = undefined;
470
+ self.Class.panel.find('ul').hide('slow').remove();
471
+ self.find('');
472
+ self.toggleRoot(true);
473
+
474
+ },
475
+
476
+ contextMenuClick : function(action, el, pos) {
477
+
478
+ var self = Window.Presenter;
479
+ if(action == 'edit') {
480
+ var type = $(el).find('a').attr('class');
481
+ var currentItem = $(el).find('a').attr('id');
482
+ self.edit(currentItem, type);
483
+ } else if(action == 'delete') {
484
+ self.delete(el);
485
+ }
486
+
487
+ },
488
+
489
+ delete : function(item) {
490
+
491
+ var self = Window.Presenter;
492
+
493
+ self.Class.controller.findCommand('rm', function(cmd) {
494
+ cmd.execute([$(item).find('a').attr('id')], function(result){
495
+ if(result.error){
496
+ self.showInfo(result.error);
497
+ return;
498
+ }
499
+ self.Class.panel.find('ul').hide('slow').remove();
500
+ self.find($(item).parent().attr('id'));
501
+ });
502
+ });
503
+
504
+ },
505
+
506
+ edit : function(ref, type) {
507
+
508
+ var self = Window.Presenter;
509
+
510
+ var currentItem = ref;
511
+
512
+ if(type == 'collection') {
513
+ self.editDialog(currentItem, "collection", function(item) {
514
+ self.refresh(Session.currentFolder);
515
+ });
516
+ } else {
517
+ self.editDialog(Session.currentFolder + "/" + currentItem, "document", function(item) {
518
+ self.refresh(Session.currentFolder);
519
+ });
520
+ }
521
+
522
+ },
523
+
524
+ new : function(item) {
525
+
526
+ var self = Window.Presenter;
527
+ var editorUrl = $(this).data('editor-url');
528
+ var typeUrl = $(this).data('type-url');
529
+
530
+ self.launchEditor(editorUrl, typeUrl, Session.currentFolder, true, function(item) {
531
+ self.refresh(item);
532
+ });
533
+
534
+ },
535
+
536
+ editDialog : function(itemUrl, type, callback){
537
+
538
+ var self = Window.Presenter;
539
+
540
+ if(type=="collection"){
541
+ self.launchEditor('/koda/koda-editors/collection-editor.html', '', itemUrl, false, callback);
542
+ } else {
543
+ self.Class.controller.findCommand('get', function(cmd) {
544
+ cmd.execute([itemUrl], function(result) {
545
+ if('_koda_editor' in result) {
546
+ self.launchEditor(result._koda_editor, result._koda_type, itemUrl, false, callback);
547
+ } else {
548
+ self.launchEditor('/koda/koda-editors/json-editor.html', '', itemUrl, false, callback);
549
+ }
550
+ });
551
+ });
552
+ }
553
+
554
+ },
555
+
556
+ launchEditor: function(base, typeUrl, itemUrl, isNew, callback) {
557
+
558
+ var fullUrl = base + "?url="+itemUrl+"&kodatype="+typeUrl+"&isnew="+isNew+"&date=" + new Date().getTime();
559
+
560
+ $("#media-trigger").attr("href", fullUrl);
561
+ $("#media-trigger").fancybox({
562
+ 'transitionIn' : 'elastic',
563
+ 'transitionOut' : 'elastic',
564
+ 'speedIn' : 300,
565
+ 'speedOut' : 100,
566
+ 'overlayShow' : true,
567
+ 'width' : 800,
568
+ 'height' : 680,
569
+ onClosed : function() {
570
+ callback(itemUrl);
571
+ }
572
+ }).trigger("click");
573
+
574
+ }
575
+ }
576
+ );
577
+
578
+ /*
579
+ ----------------------------------------------------------
580
+ Console Prompt
581
+ ----------------------------------------------------------
582
+ */
583
+
584
+ $.Class.extend("Prompt",
585
+ {
586
+ writeToInput : function(value) {
587
+
588
+ var self = $(".active:last"), input;
589
+ input = self.find('textarea');
590
+ input.val(value);
591
+
592
+ },
593
+
594
+ getInput : function() {
595
+
596
+ var self = $(".active:last"), input;
597
+ input = self.find('textarea');
598
+ return input.val();
599
+
600
+ },
601
+
602
+ writeToOutput : function(value, prompt) {
603
+
604
+ var currentFolder = Session.currentFolder == undefined ? "home" : Session.currentFolder;
605
+ var promptIndicator = prompt == undefined ? currentFolder : prompt;
606
+
607
+ var self = $(".active:last"), input, line;
608
+ var text = $('<pre/>').text(value);
609
+
610
+ line = self.clone();
611
+ if(text) self.append(text);
612
+ self.removeClass('active').addClass("inactive");
613
+ self.attr('disabled', true);
614
+ self.after( line );
615
+
616
+ $('.prompt:last').text(promptIndicator + " >");
617
+ $('.active textarea').removeClass().addClass(Prompt.multiline ? "multi" : "single")
618
+ $('.active textarea').focus().val('');
619
+
620
+ },
621
+
622
+ multiline: false,
623
+
624
+ promptInputOverride: false,
625
+
626
+ promptOverrideDelegate: undefined,
627
+ },
628
+ { init : function() {} }
629
+ );
630
+
631
+ /*
632
+ ----------------------------------------------------------
633
+ Controller
634
+ ----------------------------------------------------------
635
+ */
636
+
637
+ $.Class.extend("KodaController",
638
+ { commands: [] },
639
+ {
640
+ init : function(commands) {
641
+
642
+ this.Class.commands = commands;
643
+
644
+ },
645
+
646
+ autocomplete : function(val){
647
+
648
+ var line = val.split(' '), returnString = val;
649
+ var lastCommand = line[line.length-1];
650
+
651
+ $.each(Session.history, function(i, item) {
652
+
653
+ if(val.indexOf(item) == -1 && item.indexOf(lastCommand) === 0) {
654
+ val += " ";
655
+ returnString = val.replace(lastCommand+" ", item);
656
+ }
657
+
658
+ });
659
+
660
+ return returnString;
661
+
662
+ },
663
+
664
+ findCommand: function(val,callback) {
665
+
666
+ $.each(this.Class.commands, function(index, commandObject) {
667
+
668
+ if(val == commandObject.Class.key) {
669
+ callback(commandObject);
670
+ }
671
+
672
+ });
673
+
674
+ },
675
+
676
+ processLine : function(val, commandExecuted) {
677
+
678
+ if ( val == '' ) return;
679
+ var self = this;
680
+
681
+ var commands = val.split(' & ');
682
+ $.each(commands, function(i, item){
683
+
684
+ var commandString = item.split(' '), command;
685
+ var commandToExecute = commandString.shift();
686
+
687
+ self.findCommand(commandToExecute, function(cmd) {
688
+ command = cmd;
689
+ if(command != undefined && command != null) {
690
+
691
+ command.execute(commandString, commandExecuted);
692
+
693
+ } else {
694
+
695
+ commandExecuted("Command not found!");
696
+ }
697
+ });
698
+
699
+ });
700
+
701
+ }
702
+
703
+ });
704
+
705
+
706
+ /*
707
+ ----------------------------------------------------------
708
+ Commands
709
+ ----------------------------------------------------------
710
+ */
711
+
712
+ $.Class.extend("CdCommand",
713
+ {
714
+ key: "cd",
715
+ help: "usage: 'cd articles' and 'cd ..'",
716
+ restService: {}
717
+ },
718
+ {
719
+ init : function(restService) {
720
+ this.Class.restService = restService;
721
+ },
722
+
723
+ execute: function(args, callback) {
724
+
725
+ if(args[0] == ".."){
726
+ Session.currentFolder = undefined;
727
+ callback();
728
+ } else {
729
+
730
+ this.Class.restService.get(args[0], function(data) {
731
+
732
+ if(data != undefined && data != null) {
733
+ Session.currentFolder = args[0];
734
+ callback();
735
+ } else {
736
+ callback("folder not found!");
737
+ }
738
+
739
+ });
740
+
741
+ }
742
+
743
+ }
744
+
745
+ }
746
+ );
747
+
748
+ $.Class.extend("MkDirCommand",
749
+ {
750
+ key: "mkdir",
751
+ help: "usage: 'mkdir [dirname]' creates a folder",
752
+ restService: {}
753
+ },
754
+ {
755
+ init : function(restService) {
756
+ this.Class.restService = restService;
757
+ },
758
+
759
+ execute: function(args, callback) {
760
+
761
+ path = Session.currentFolder == undefined ? StringUtil.empty : Session.currentFolder;
762
+ if(path == StringUtil.empty) {
763
+
764
+ MkDirCommand.restService.post(args[0], '{"alias":"_delete"}', function(sdata) {
765
+
766
+ if(sdata == "OK") {
767
+ MkDirCommand.restService.delete(args[0] + "/_delete", function(ddata) {
768
+
769
+ if(ddata == "OK"){
770
+ callback("folder created");
771
+ }
772
+
773
+ });
774
+ } else {
775
+ callback("folder could not be created, "+sdata);
776
+ }
777
+
778
+ });
779
+
780
+ } else {
781
+
782
+ callback("at the moment folders can only be created in root dir");
783
+
784
+ }
785
+
786
+ }
787
+
788
+ }
789
+ );
790
+
791
+ $.Class.extend("EditCommand",
792
+ {
793
+ key: "edit",
794
+ help: "usage: 'edit [resource]' (will create if not exist)",
795
+ restService: {}
796
+ },
797
+ {
798
+ init : function(restService) {
799
+ this.Class.restService = restService;
800
+ },
801
+
802
+ execute: function(args, callback) {
803
+
804
+ path = Session.currentFolder == undefined ? StringUtil.empty : Session.currentFolder;
805
+ if(path == StringUtil.empty || path.indexOf("_koda_media") != -1) {
806
+
807
+ callback("cannot create resources in either root or media folder");
808
+
809
+ } else {
810
+
811
+ Session.currentEditor = {};
812
+ Prompt.multiline = true;
813
+ var editor = this.editor;
814
+ Session.currentEditor.path = path + "/" + args[0];
815
+
816
+ Session.currentEditor.callback = callback;
817
+
818
+ this.Class.restService.get(Session.currentEditor.path, function(data) {
819
+
820
+ Prompt.writeToOutput("--hit CTRL+C when done---", "")
821
+
822
+ if(data == null) {
823
+ Prompt.writeToInput('{"alias":"'+args[0]+'"}')
824
+ Session.currentEditor.state = "NEW";
825
+ } else {
826
+ Prompt.writeToInput(JSON.stringify(data, null, 2))
827
+ Session.currentEditor.state = "OLD";
828
+ }
829
+
830
+ Prompt.promptInputOverride = true;
831
+ Prompt.promptOverrideDelegate = editor;
832
+
833
+ });
834
+
835
+ }
836
+
837
+ },
838
+
839
+ editor: function(input) {
840
+
841
+ Prompt.promptInputOverride = false;
842
+ Prompt.promptOverrideDelegate = undefined;
843
+ Prompt.multiline = false;
844
+ var callback = Session.currentEditor.callback;
845
+
846
+ if(Session.currentEditor.state == "NEW") {
847
+
848
+ EditCommand.restService.post(Session.currentFolder, input, function(data) {
849
+
850
+ if(data == "OK") {
851
+ callback("the item was created");
852
+ } else {
853
+ callback("server unavailable or not valid json: ");
854
+ }
855
+
856
+ });
857
+
858
+ } else {
859
+
860
+ EditCommand.restService.put(Session.currentEditor.path, input, function(data) {
861
+
862
+ if(data == "OK") {
863
+ callback("the item was saved");
864
+ } else {
865
+ callback("server unavailable or not valid json: ");
866
+ }
867
+
868
+ });
869
+
870
+ }
871
+
872
+
873
+ }
874
+
875
+ }
876
+ );
877
+
878
+ $.Class.extend("HelpCommand",
879
+ {
880
+ key: "help",
881
+ help: "usage: type 'help' at any time",
882
+ commands: []
883
+ },
884
+ {
885
+ init : function(commands) {
886
+
887
+ if(commands != undefined){
888
+ this.Class.commands = commands;
889
+ } else {
890
+ this.Class.commands = Session.commands;
891
+ }
892
+
893
+ },
894
+
895
+ execute: function(args, callback) {
896
+
897
+ var output = StringUtil.empty;
898
+
899
+ $.each(this.Class.commands, function(i, item){
900
+
901
+ output += StringUtil.format("{0} - {1}\n", item.Class.key, item.Class.help);
902
+
903
+ });
904
+
905
+ callback(output);
906
+ }
907
+
908
+ }
909
+ );
910
+
911
+ $.Class.extend("LsCommand",
912
+ {
913
+ key: "ls",
914
+ help: "usage: 'ls' in any folder to list resources",
915
+ restService: {}
916
+ },
917
+ {
918
+ init : function(restService) {
919
+ this.Class.restService = restService;
920
+ },
921
+
922
+ execute: function(args, callback) {
923
+
924
+ if(args != undefined && args.length > 0){
925
+
926
+ callback("wrong number of arguments!");
927
+
928
+ } else {
929
+
930
+ var lookup = Session.currentFolder == undefined ? StringUtil.empty : Session.currentFolder;
931
+ Session.history = [];
932
+ this.Class.restService.get(lookup, function(data) {
933
+ var output = StringUtil.empty;
934
+
935
+ if(data.constructor == Array) {
936
+ $.each(data, function(i, item){
937
+
938
+ var href = item.href;
939
+ var count = href.split("/").length - 1
940
+ var indicator = count > 2 ? "<FILE> " : "<DIR> ";
941
+ output += indicator+item.alias + "\n";
942
+ Session.history.push(item.alias);
943
+
944
+ });
945
+ } else {
946
+ output += "<FILE> "+data.alias + "\n";
947
+ Session.history.push(data.alias);
948
+ }
949
+
950
+ callback(output);
951
+
952
+ });
953
+
954
+ }
955
+
956
+ }
957
+
958
+ }
959
+ );
960
+
961
+ $.Class.extend("ListCommand",
962
+ {
963
+ key: "list",
964
+ help: "usage: 'list' in any folder to list resources as array",
965
+ restService: {}
966
+ },
967
+ {
968
+ init : function(restService) {
969
+ this.Class.restService = restService;
970
+ },
971
+
972
+ execute: function(args, callback) {
973
+
974
+ this.Class.restService.get(args[0].toLowerCase(), function(data) {
975
+
976
+ if(data.error){
977
+ callback(data);
978
+ return;
979
+ }
980
+ var output = [];
981
+
982
+ if(data.constructor == Array) {
983
+ $.each(data, function(i, item){
984
+ var href = item.href;
985
+ var count = href.split("/").length - 1
986
+ var indicator = count > 2 ? "file" : "collection";
987
+ var name = item.name ? item.name : item.title
988
+ output.push({ id: item.alias, name : name, _koda_type : item._koda_type, type: indicator, date_created : item.date_created });
989
+
990
+ });
991
+ } else {
992
+ var name = item.name ? item.name : item.title
993
+ output.push({ id: data.alias, name : name, _koda_type : data._koda_type, type: 'file', date_created : data.date_created });
994
+ }
995
+
996
+ callback(output);
997
+
998
+ });
999
+
1000
+ }
1001
+
1002
+ }
1003
+ );
1004
+
1005
+ $.Class.extend("OpenCommand",
1006
+ {
1007
+ key: "open",
1008
+ help: "usage: 'open [resource]' this will open the resource in a window",
1009
+ kodaUrl: ''
1010
+ },
1011
+ {
1012
+ init : function() {
1013
+ this.Class.kodaUrl = Session.kodaUrl;
1014
+ },
1015
+
1016
+ execute: function(args, callback) {
1017
+
1018
+ var lookup = Session.currentFolder == undefined ? StringUtil.empty : Session.currentFolder;
1019
+ var url = this.Class.kodaUrl + "/" + lookup + "/" +args[0];
1020
+
1021
+ $("#media-trigger").attr("href", url.toLowerCase());
1022
+ $("#media-trigger").fancybox({
1023
+ 'transitionIn' : 'elastic',
1024
+ 'transitionOut' : 'elastic',
1025
+ 'speedIn' : 600,
1026
+ 'speedOut' : 200,
1027
+ 'overlayShow' : false,
1028
+ 'width' : 800,
1029
+ 'height' : 600
1030
+ }).trigger("click");
1031
+
1032
+ $('#fancybox-frame').addClass('prettyprint');
1033
+ callback("opening...");
1034
+
1035
+ }
1036
+
1037
+ }
1038
+ );
1039
+
1040
+ $.Class.extend("PeekCommand",
1041
+ {
1042
+ key: "peek",
1043
+ help: "usage: 'peek [resource]' will show contents if json",
1044
+ restService: {}
1045
+ },
1046
+ {
1047
+ init : function(restService) {
1048
+ this.Class.restService = restService;
1049
+ },
1050
+
1051
+ execute: function(args, callback) {
1052
+
1053
+ var lookup = Session.currentFolder == undefined ? StringUtil.empty : Session.currentFolder;
1054
+
1055
+ this.Class.restService.get(lookup + "/" +args[0], function(data) {
1056
+
1057
+ callback(JSON.stringify(data, null, 2));
1058
+
1059
+ });
1060
+
1061
+ }
1062
+
1063
+ }
1064
+ );
1065
+
1066
+ $.Class.extend("GetCommand",
1067
+ {
1068
+ key: "get",
1069
+ help: "view: not for use with console",
1070
+ restService: {}
1071
+ },
1072
+ {
1073
+ init : function(restService) {
1074
+ this.Class.restService = restService;
1075
+ },
1076
+
1077
+ execute: function(args, callback) {
1078
+
1079
+ this.Class.restService.get(args[0].toLowerCase(), function(data) {
1080
+
1081
+ callback(data);
1082
+
1083
+ });
1084
+
1085
+ }
1086
+
1087
+ }
1088
+ );
1089
+
1090
+ $.Class.extend("RemoveCommand",
1091
+ {
1092
+ key: "rm",
1093
+ help: "usage: 'rm [resource]' removes a resource",
1094
+ restService: {}
1095
+ },
1096
+ {
1097
+ init : function(restService) {
1098
+
1099
+ this.Class.restService = restService;
1100
+
1101
+ },
1102
+
1103
+ execute: function(args, callback) {
1104
+
1105
+ var lookup = Session.currentFolder == undefined ? args[0] : Session.currentFolder + "/" + args[0];
1106
+
1107
+ this.Class.restService.delete(lookup.toLowerCase(), function(data) {
1108
+
1109
+ if(data == "OK"){
1110
+ callback("the item was deleted");
1111
+ } else{
1112
+ callback(data);
1113
+ }
1114
+
1115
+ });
1116
+
1117
+ }
1118
+
1119
+ }
1120
+ );
1121
+
1122
+ $.Class.extend("Session", {history:[]}, {});
1123
+
1124
+ /*
1125
+
1126
+ Entries
1127
+
1128
+ */
1129
+
1130
+ $.Class.extend("Explorer", {}, {
1131
+ init: function(currentUrl) {
1132
+ var url = currentUrl;
1133
+ var arr = url.split("/");
1134
+ var result = arr[0] + "//" + arr[2] + '/api'
1135
+
1136
+ Session.kodaUrl = result;
1137
+
1138
+ var service = new RestService();
1139
+ var commands = Session.commands = [];
1140
+ commands.push(new CdCommand(service));
1141
+ commands.push(new ListCommand(service));
1142
+ commands.push(new RemoveCommand(service));
1143
+ commands.push(new OpenCommand());
1144
+ commands.push(new MkDirCommand(service));
1145
+ commands.push(new GetCommand(service));
1146
+
1147
+ service.getExternal('/session/current_user', function(user){
1148
+
1149
+ Window.current_user = user;
1150
+
1151
+ service.getExternal('/koda/koda-types/_builtin_registration.json', function(builtin){
1152
+
1153
+ service.getExternal('/koda/koda-types/type_registration.json', function(custom){
1154
+ var data = builtin.concat(custom);
1155
+ var controller = new KodaController(commands);
1156
+ Window.Presenter = new ExplorerPresenter(controller, data);
1157
+ Window.Presenter.attach();
1158
+ })
1159
+
1160
+ })
1161
+
1162
+ });
1163
+ }
1164
+ });
1165
+
1166
+ $.Class.extend("Console", {}, {
1167
+ init: function(currentUrl) {
1168
+ var url = currentUrl;
1169
+ var arr = url.split("/");
1170
+ var result = arr[0] + "//" + arr[2] + '/api'
1171
+
1172
+ Session.kodaUrl = result;
1173
+
1174
+ var service = new RestService();
1175
+ var commands = Session.commands = [];
1176
+
1177
+ commands.push(new HelpCommand());
1178
+ commands.push(new PeekCommand(service));
1179
+ commands.push(new CdCommand(service));
1180
+ commands.push(new LsCommand(service));
1181
+ commands.push(new EditCommand(service));
1182
+ commands.push(new RemoveCommand(service));
1183
+ commands.push(new OpenCommand());
1184
+ commands.push(new MkDirCommand(service));
1185
+
1186
+ var controller = new KodaController(commands);
1187
+ Window.Presenter = new ConsolePresenter(controller);
1188
+ Window.Presenter.attach();
1189
+ }
1190
+ });
1191
+
1192
+ /* Static Void Main */
1193
+
1194
+ (function() {
1195
+ if(Window.Application == "Explorer") {
1196
+ new Explorer(window.location.href);
1197
+ } else if(Window.Application == "Console") {
1198
+ new Console(window.location.href);
1199
+ }
1200
+ })()