wiki_sidebar.mustache 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <%
  2. # Copyright (C) 2011 - present Instructure, Inc.
  3. #
  4. # This file is part of Canvas.
  5. #
  6. # Canvas is free software: you can redistribute it and/or modify it under
  7. # the terms of the GNU Affero General Public License as published by the Free
  8. # Software Foundation, version 3 of the License.
  9. #
  10. # Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. # details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License along
  16. # with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %>
  18. <% @context ||= @current_user %>
  19. <% cache(['wiki_sidebar_render_3', @context.cache_key, @current_user, @context.feature_enabled?(:usage_rights_required)].cache_key.to_s) do %>
  20. <% load_wiki_sidebar %>
  21. <% show_files_tab = @wiki_sidebar_data[:root_folders].any?{|rf| rf.grants_right?(@current_user, session, :read_contents)} %>
  22. <div id="editor_tabs" class="ui-tabs--mini" style="display: none;">
  23. <span class="wiki-sidebar-header" role="heading" aria-level="2">{{#t}}Insert Content into the Page{{/t}}</span>
  24. <ul>
  25. <li><a href="#editor_tabs_2">{{#t}}Links{{/t}}</a></li>
  26. <% if show_files_tab %>
  27. <li><a href="#editor_tabs_3">{{#t}}Files{{/t}}</a></li>
  28. <% end %>
  29. <li><a href="#editor_tabs_4">{{#t}}Images{{/t}}</a></li>
  30. </ul>
  31. <div id="editor_tabs_2" role="application">
  32. <%= @context.is_a?(Group) ? t('group_links', 'Link to other content in the group.') : t('course_links', 'Link to other content in the course.') %>
  33. <% if @context.is_a?(Course) || @context.is_a?(Group) %>
  34. <a href="<%= context_url(@context, :retrieve_context_external_tools_url, :url => "{{ url }}") %>" id="external_tool_retrieve_url" style="display: none;">&nbsp;</a>
  35. <% end %>
  36. <% if @context.is_a?(Course) %>
  37. <a href="<%= context_url(@context, :context_external_tool_resource_selection_url, "{{ id }}", :editor => '1') %>" id="context_external_tool_resource_selection_url" style="display: none;">&nbsp;</a>
  38. <% end %>
  39. {{#t}}Click any page to insert a link to that page.{{/t}}
  40. <div id="pages_accordion" class="ui-accordion--mini" role="tabpanel">
  41. <% if @context.respond_to?(:wiki) %>
  42. <a href="<%= polymorphic_url([@context, :wiki_page], id: '{{ page_url }}') %>" id="wiki_sidebar_wiki_url" style="display: none;">&nbsp;</a>
  43. <div>
  44. <div class="header" aria-controls="pages_tab_panel" role="tab"><a href="#">{{#t}}Pages{{/t}}</a></div>
  45. <div id="pages_tab_panel" role="tabpanel">
  46. <ul class="wiki_pages page_list">
  47. <% (@wiki_sidebar_data[:wiki_pages]).each do |wiki_page| %>
  48. <% if can_do(@wiki_sidebar_data[:wiki], @current_user, :manage) || wiki_page.published? %>
  49. <li title="{{#t}}Click to insert a link to this page{{/t}}"><%= link_to wiki_page.title, polymorphic_path([@context, wiki_page]), :role => "button"%></li>
  50. <% end %>
  51. <% end %>
  52. </ul>
  53. <% if can_do(@wiki_sidebar_data[:wiki], @current_user, :create_page) %>
  54. <%= link_to t('links.new_page', "Link to a New Page"), "#", :id => 'new_page_link', :class => "icon-add" %>
  55. <form id="new_page_drop_down" style="display:none; margin: 5px;">
  56. <div class="row-fluid">
  57. <label for="new_page_name">{{#t}}What would you like to call the new page?{{/t}}</label><br />
  58. <input type="text" name="new_page_name" id="new_page_name" class="span12">
  59. <input type="hidden" name="new_page_url_prefix" value="<%= polymorphic_path([@context, :wiki_pages]) %>" id="new_page_url_prefix" />
  60. <button id="new_page_submit" class="btn btn-small" type="submit">{{#t}}Insert Link{{/t}}</button>
  61. </div>
  62. </form>
  63. <% end %>
  64. </div>
  65. </div>
  66. <% end %>
  67. <% if @context.respond_to?(:assignments) %>
  68. <div>
  69. <div aria-controls="assignment_panel" role="tab" class="header" aria-controls="wiki_pages_panel"><a href="#">{{#t}}Assignments{{/t}}</a></div>
  70. <div id="assignment_panel" role="tabpanel">
  71. <ul class="wiki_pages page_list">
  72. <li title="{{#t}}Click to insert a link to this assignment{{/t}}"><%= link_to t('links.assignments', "Assignments"), context_url(@context, :context_assignments_url)%></li>
  73. <% for assignment in @wiki_sidebar_data[:active_assignments].select{|a| !a.new_record?} %>
  74. <li title="{{#t}}Click to insert a link to this assignment{{/t}}"><%= link_to assignment.title, context_url(@context, :context_assignment_url, assignment) %></li>
  75. <% end %>
  76. </ul>
  77. </div>
  78. </div>
  79. <% end %>
  80. <% if @context.respond_to?(:quizzes) %>
  81. <div>
  82. <div aria-controls="quizzes_panel" class="header" role="tab"><a href="#">{{#t}}Quizzes{{/t}}</a></div>
  83. <div id="quizzes_panel" role="tabpanel">
  84. <ul class="wiki_pages page_list">
  85. <li title="{{#t}}Click to insert a link to this quiz{{/t}}"><%= link_to t('links.quizzes', "Quizzes"), context_url(@context, :context_quizzes_url) %></li>
  86. <% for quiz in @wiki_sidebar_data[:active_quizzes].select{|a| !a.new_record?} %>
  87. <li title="{{#t}}Click to insert a link to this quiz{{/t}}"><%= link_to quiz.title, context_url(@context, :context_quiz_url, quiz) %></li>
  88. <% end %>
  89. </ul>
  90. </div>
  91. </div>
  92. <% end %>
  93. <% if @context.respond_to?(:announcements) %>
  94. <div>
  95. <div class="header" aria-controls="announcements_panel" role="tab"><a href="#">{{#t}}Announcements{{/t}}</a></div>
  96. <div id="announcements_panel" role="tabpanel">
  97. <ul class="wiki_pages page_list">
  98. <li title="{{#t}}Click to insert a link to this announcement{{/t}}"><%= link_to t('links.announcements', "Announcements"), context_url(@context, :context_announcements_url) %></li>
  99. <% for announcement in @wiki_sidebar_data[:active_discussion_topics].select{ |d| d.is_a?(Announcement) } %>
  100. <li title="{{#t}}Click to insert a link to this announcement{{/t}}"><%= link_to announcement.title, context_url(@context, :context_announcement_url, announcement) %></li>
  101. <% end %>
  102. </ul>
  103. </div>
  104. </div>
  105. <% end %>
  106. <% if @context.respond_to?(:discussion_topics) %>
  107. <div>
  108. <div role="tab" aria-controls="discussions_panel" class="header"><a href="#">{{#t}}Discussions{{/t}}</a></div>
  109. <div id="discussions_panel" role="tabpanel">
  110. <ul class="wiki_pages page_list">
  111. <li title="{{#t}}Click to insert a link to this topic{{/t}}"><%= link_to t('links.discussions', "Discussions"), context_url(@context, :context_discussion_topics_url) %></li>
  112. <% for discussion_topic in @wiki_sidebar_data[:active_discussion_topics].reject{ |d| d.is_a?(Announcement) } %>
  113. <li title="{{#t}}Click to insert a link to this topic{{/t}}"><%= link_to discussion_topic.title, context_url(@context, :context_discussion_topic_url, discussion_topic) %></li>
  114. <% end %>
  115. </ul>
  116. </div>
  117. </div>
  118. <% end %>
  119. <% if @context.respond_to?(:context_modules) %>
  120. <div>
  121. <div role="tab" aria-controls="modules_panel" class="header"><a href="#">{{#t}}Modules{{/t}}</a></div>
  122. <div id="modules_panel" role="tabpanel">
  123. <ul class="wiki_pages page_list">
  124. <li title="{{#t}}Click to insert a link to this module{{/t}}"><%= link_to t('links.modules', "Modules"), context_url(@context, :context_context_modules_url) %></li>
  125. <% for m in @wiki_sidebar_data[:active_context_modules] %>
  126. <li title="{{#t}}Click to insert a link to this module{{/t}}"><%= link_to m.name, context_url(@context, :context_context_module_url, m) %></li>
  127. <% end %>
  128. </ul>
  129. </div>
  130. </div>
  131. <% end %>
  132. <div>
  133. <div class="header" role="tab" aria-controls="groups_panel"><a href="#"><%= @context.is_a?(Group) ? t('links_to.nav.group', 'Group Navigation') : t('links_to.nav.course', 'Course Navigation') %></a></div>
  134. <div role="tabpanel" id="groups_panel">
  135. <ul class="wiki_pages page_list">
  136. <% if @context.respond_to?(:assignments) %>
  137. <li title="{{#t}}Click to insert a link to the assignments page{{/t}}"><%= link_to t('links.assignments_page', "Assignments"), context_url(@context, :context_assignments_url)%></li>
  138. <% end %>
  139. <% if @context.respond_to?(:wiki) %>
  140. <li title="{{#t}}Click to insert a link to the wiki{{/t}}"><%= link_to t('links.wiki_pages_index', "Pages"), polymorphic_url([@context, :wiki_pages]) %></li>
  141. <% end %>
  142. <% if @context.respond_to?(:discussion_topics) %>
  143. <li title="{{#t}}Click to insert a link to the discussions page{{/t}}"><%= link_to t('links.discussions_page', "Discussions"), context_url(@context, :context_discussion_topics_url)%></li>
  144. <% end %>
  145. <% if @context.respond_to?(:assignments) %>
  146. <li title="{{#t}}Click to insert a link to the syllabus{{/t}}"><%= link_to t('links.syllabus', "Syllabus"), context_url(@context, :syllabus_context_assignments_url)%></li>
  147. <% end %>
  148. <% if @context.respond_to?(:announcements) %>
  149. <li title="{{#t}}Click to insert a link to the announcements page{{/t}}"><%= link_to t('links.announcements_page', "Announcements"), context_url(@context, :context_announcements_url)%></li>
  150. <% end %>
  151. <% if @context.respond_to?(:attachments) %>
  152. <li title="{{#t}}Click to insert a link to the files page{{/t}}"><%= link_to t('links.files_page', "Files"), context_url(@context, :context_files_url)%></li>
  153. <% end %>
  154. <% collaborations_url = context_url(@context, :context_collaborations_url) rescue nil %>
  155. <% if collaborations_url %>
  156. <li title="{{#t}}Click to insert a link to the collaborations page{{/t}}"><%= link_to t('links.collaborations_page', "Collaborations"), collaborations_url%></li>
  157. <% end %>
  158. <% if @context.is_a?(Course) %>
  159. <li title="{{#t}}Click to insert a link to the grades page{{/t}}"><%= link_to t('links.grades_page', "Grades"), context_url(@context, :context_grades_url)%></li>
  160. <% end %>
  161. <% if @context.respond_to?(:users) %>
  162. <li title="{{#t}}Click to insert a link to the people page{{/t}}"><%= link_to t('links.users_page', "People"), context_url(@context, :context_users_url)%></li>
  163. <% end %>
  164. <% if @context.respond_to?(:context_modules) %>
  165. <li title="{{#t}}Click to insert a link to the modules page{{/t}}"><%= link_to t('links.modules_page', "Modules"), context_url(@context, :context_context_modules_url)%></li>
  166. <% end %>
  167. </ul>
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. <% if show_files_tab %>
  173. <div id="editor_tabs_3">
  174. {{#t}}Click any file to insert a download link for that file.{{/t}}
  175. <div id="wiki_sidebar_file_uploads" class="uploading_file_list" style="display: none;">
  176. <div class="uploading">
  177. {{#t}}uploading_file', %{Uploading *file*...}, :wrapper => '<span class="filename">\1</span>{{/t}}
  178. <div>
  179. <%= image_tag "ajax-loader-bar.gif", :alt => t('images.alt.loading', "Loading...") %>
  180. </div>
  181. </div>
  182. <div class="remaining">
  183. <%= t 'files_remaining', '*0* more to upload', :wrapper => '<span class="files_remaining">\1</span>' %>
  184. </div>
  185. </div>
  186. <div class="file_list_holder <%= 'file_drop' if can_do(@context, @current_user, :manage_files) %>">
  187. <div class="dragging_message">{{#t}}Drop Files Here to upload{{/t}}</div>
  188. <div id="file_list_container" class="file_list" style="max-height: 300px; overflow: auto;">
  189. <a id="folder_url" href="<%= context_url(@context, :context_folder_url, '{{ id }}').html_safe %>" style="display: none;">&nbsp;</a>
  190. <ul id="tree1" role="tree" data-level="0" tabindex="0" aria-label="{{#t}}Files, Use the up and down arrow keys to navigate through the tree. Press right to expand folders, left to collapse {{/t}}">
  191. <% @wiki_sidebar_data[:root_folders].each do |folder| %>
  192. <li aria-level="0" aria-selected="false" role="treeitem" data-id="<%= folder.id %>" class="folder folder_<%= folder.id %>" id="root_folder_<%= folder.id %>">
  193. <span class='name'><%= folder.name %> </span>
  194. <ul role="group"></ul>
  195. </li>
  196. <% end %>
  197. <li aria-selected="false" role="treeitem" class="file file_blank" style="display: none;">
  198. <span class='name' rel="<%= context_url(@context, :context_url) %>/files/{{ id }}/download?wrap=1"></span>
  199. </li>
  200. <li aria-selected="false" role="treeitem" class="folder_blank" style="display: none;">
  201. <span class='name'></span>
  202. <ul role="group"></ul>
  203. </li>
  204. <li class="loading" style="display: none;">
  205. <%= t 'messages.loading', "Loading..." %>
  206. </li>
  207. </ul>
  208. </div>
  209. </div>
  210. <% if can_do(@context, @current_user, :manage_files) %>
  211. <div><a href="#" class="upload_new_file_link icon-add" style="padding-top:2px;">{{#t}}Upload a new file{{/t}}</a></div>
  212. <%= form_for :attachment, :url => context_url(@context, :context_files_url), :html => {:id => "sidebar_upload_file_form", :style => "display: none;", :multipart => true, :class => "sidebar_upload_file_form"} do |f| %>
  213. <input type="hidden" name="return_to" value="<%= request.url %>"/>
  214. <%= f.file_field :uploaded_data, :class => "file_name", :size => 20 %>
  215. <% if !@wiki_sidebar_data[:root_folders].empty? %>
  216. <div>
  217. <div>{{#t}}file_size_limit', %{limit %{size} per file}, :size => '50MB{{/t}}</div>
  218. <label for="attachment_folder_id">{{#t}}Folder{{/t}}</label>
  219. <select name="attachment[folder_id]" id="attachment_folder_id" class="attachment_folder_id">
  220. <% @wiki_sidebar_data[:root_folders].each do |folder| %>
  221. <option value="<%= folder.id %>"><%= folder.name %></option>
  222. <% end %>
  223. </select>
  224. <div id="usage-rights" data-usage-rights-required="<%= @context.feature_enabled?(:usage_rights_required) %>"></div>
  225. </div>
  226. <% end %>
  227. <div class="uploading" style="display: none; text-align: center;">
  228. <%= image_tag "ajax-loader-bar.gif", :alt => t('images.alt.loading', "Loading...") %>
  229. </div>
  230. <div class="button-container">
  231. <button class="btn uploadFileBtn" type="submit">{{#t}}Upload{{/t}}</button>
  232. </div>
  233. <a href="<%= context_url(@context, :context_files_url, :format => :json) %>" class="json_upload_url" style="display: none;">&nbsp;</a>
  234. <a href="<%= context_url(@context, :context_file_download_url, "{{ id }}", :wrap => 1) %>" class="file_url" style="display: none;">&nbsp;</a>
  235. <% end %>
  236. <% end %>
  237. </div>
  238. <% end %>
  239. <div aria-atomic="true" id="editor_tabs_4">
  240. {{#t}}Click any image to embed the image in the page.{{/t}}
  241. <% if can_do(@context, @current_user, :manage_files) %>
  242. <a href="#" aria-label="{{#t}}Click to toggle the upload a new image form (collapsed){{/t}}" class="upload_new_image_link icon-add" style="padding-top:2px;">{{#t}}Upload a new image{{/t}}</a>
  243. <% end %>
  244. <% if can_do(@context, @current_user, :manage_files) %>
  245. <%= form_for :attachment, :url => context_url(@context, :context_files_url), :html => {:id => "sidebar_upload_image_form", :style => "display: none;", :multipart => true} do |f| %>
  246. <input type="hidden" name="return_to" value="<%= request.url %>"/>
  247. <div style="margin-left: 10px;">
  248. <label for="image_folder_id">{{#t}}Folder{{/t}}</label>
  249. <select name="attachment[folder_id]" id="image_folder_id" aria-label="{{#t}}Select a folder to upload your image into{{/t}}">
  250. <% @wiki_sidebar_data[:root_folders].each do |folder| %>
  251. <option value="<%= folder.id %>"><%= folder.name %></option>
  252. <% end %>
  253. </select>
  254. <%= f.file_field :uploaded_data, :class => "file_name", :size => 20, :'aria-label' => t("aria.file_label", "Select a file, Upload limit 50") %>
  255. <label style="font-size: 11px" for="attachment_uploaded_data">{{#t}}file_size_limit', %{limit %{size} per file}, :size => '50MB{{/t}}</label>
  256. <div class="uploading" style="display: none; text-align: center;">
  257. <%= image_tag "ajax-loader-bar.gif", :alt => t('images.alt.loading', "Loading...") %>
  258. </div>
  259. </div>
  260. <div class="button-container">
  261. <button class="btn " type="submit">{{#t}}Upload{{/t}}</button>
  262. </div>
  263. <a href="<%= context_url(@context, :context_files_url, :format => :json) %>" class="json_upload_url" style="display: none;">&nbsp;</a>
  264. <a href="<%= context_url(@context, :context_file_preview_url, "{{ id }}") %>" class="file_url" style="display: none;">&nbsp;</a>
  265. <% end %>
  266. <% end %>
  267. <div>
  268. <a tabindex="0" href="#" class="find_new_image_link find">{{#t}}Find images on flickr creative commons{{/t}}</a>
  269. </div>
  270. <div id="wiki_sidebar_image_uploads" class="uploading_file_list uploading_image_list" style="display: none;">
  271. <div class="uploading">
  272. {{#t}}uploading_file', %{Uploading *file*...}, :wrapper => '<span class="filename">\1</span>{{/t}}
  273. <div>
  274. <%= image_tag "ajax-loader-bar.gif", :alt => t('images.alt.loading', "Loading...") %>
  275. </div>
  276. </div>
  277. <div class="remaining">
  278. <%= t 'files_remaining', '*0* more to upload', :wrapper => '<span class="files_remaining">\1</span>' %>
  279. </div>
  280. {{> views/shared/wiki_image}}
  281. </div>
  282. <div class="image_list_holder <%= 'file_drop' if can_do(@context, @current_user, :manage_files) %>">
  283. <div class="dragging_message">{{#t}}Drop Images Here to upload{{/t}}</div>
  284. <div class="image_list" style="max-height: 300px; overflow: auto;" data-url="<%= context_url(@context, :context_images_url) %>">
  285. </div>
  286. </div>
  287. </div>
  288. <div style="display: none;">
  289. <a href="<%= services_path(:service_type => "BookmarkService") %>" class="bookmark_services_url">&nbsp;</a>
  290. <a href="<%= bookmark_search_path(:service_type => "{{ service_type }}", :q => "{{ query }}") %>" class="bookmark_search_url">&nbsp;</a>
  291. <span class="context_code"><%= @context.asset_string %></span>
  292. <div id="wiki_sidebar_select_folder_dialog">
  293. <%= t 'select_destination', 'Select a destination folder for these %{count} files:', :count => '<span class="file_count">&nbsp;</span>'.html_safe %>
  294. <div style="margin: 20px;">
  295. <select class="folder_id">
  296. <% @wiki_sidebar_data[:root_folders].each do |folder| %>
  297. <option value="<%= folder.id %>"><%= folder.name %></option>
  298. <% end %>
  299. </select>
  300. </div>
  301. <div class="button-container">
  302. <button type="button" class="btn select_button">{{#t}}Upload Files to Folder{{/t}}</button>
  303. <button type="button" class="btn cancel_button btn button-secondary">{{#t}}Cancel{{/t}}</button>
  304. </div>
  305. </div>
  306. </div>
  307. </div>
  308. <% end %>