Advertisement
Guest User

Untitled

a guest
Sep 19th, 2015
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.00 KB | None | 0 0
  1. @model MentorsTeachers.Models.CatsAndTeachersAndOneLesson
  2.  
  3. @{
  4. Layout = "~/Views/Shared/_LoggedInLayout.cshtml";
  5. }
  6.  
  7.  
  8. <div class="container instrument">
  9.  
  10. <ul id="instrument-list">
  11. @foreach (MentorsTeachers.Models.CategoryModel category in Model.categories)
  12. {
  13. <li id=@category.CategoryId class="current-instrument">
  14. <img src=@category.Picture>
  15. <h4 id="instrument-cat">@category.CategoryName</h4>
  16. </li>
  17. }
  18. </ul>
  19. </div>
  20.  
  21. <div class="container" id="student-teachers">
  22. <h3>My Teachers</h3>
  23.  
  24. <ul id="student-teacher">
  25.  
  26. @foreach (var teacher in Model.teachers.Where(x => x.categoryId == ViewBag.selectedCategory).Distinct())
  27. {
  28. <li id=@teacher.ID class="current-teacher">
  29. <img src=@teacher.PictureUrl>
  30. <h4>@teacher.FirstName @teacher.LastName</h4>
  31. </li>
  32. }
  33. </ul>
  34.  
  35. </div>
  36.  
  37. <div class="container" id="lesson-body">
  38.  
  39. <div id="avatar">
  40.  
  41. <img src="http://placehold.it/300.png/09f/fff">
  42. <h4>You</h4>
  43.  
  44. </div>
  45.  
  46. <div id="post-box">
  47.  
  48. <textarea cols="50" rows="5" placeholder="Write message"></textarea>
  49.  
  50. <button class="btn btn-default" id="upload-video-btn">Upload Video</button>
  51.  
  52. <button class="btn btn-default" id="post-btn">Post</button>
  53.  
  54. </div>
  55.  
  56. <div class="container" id="chat-area">
  57.  
  58. @foreach (var message in Model.lesson.messages)
  59. {
  60. if (message.IsFromTeacher)
  61. {
  62. <ul id="teacher-post">
  63. <li id="teacher-video">
  64. @if (!string.IsNullOrEmpty(message.VideoUrl))
  65. {
  66. <iframe width="350" height="200" src=@message.VideoUrl frameborder="0" allowfullscreen></iframe>
  67. }
  68. @if (!string.IsNullOrEmpty(message.Text))
  69. {
  70. <p id="teacher-message">@message.Text</p>
  71. }
  72. </li>
  73. <li id="teacher-avatar">
  74. <img src=@Model.firstSelectedTeacherPicUrl>
  75. <h4>@Model.firstSelectedTeacherName</h4>
  76. </li>
  77. </ul>
  78. }
  79. else
  80. {
  81. <ul id="student-post">
  82. <li id="student-avatar">
  83. <img src=@Model.myPicUrl>
  84. <h4>You</h4>
  85. </li>
  86. <li id="student-video">
  87. @if (!string.IsNullOrEmpty(message.VideoUrl))
  88. {
  89. <iframe width="350" height="200" src=@message.VideoUrl frameborder="0" allowfullscreen></iframe>
  90. }
  91. @if (!string.IsNullOrEmpty(message.Text))
  92. {
  93. <p id="student-message">@message.Text</p>
  94. }
  95. </li>
  96. </ul>
  97. }
  98. }
  99. @*<ul id="teacher-post">
  100. <li id="teacher-video">
  101.  
  102. <iframe width="350" height="200" src="https://www.youtube.com/embed/OWsyrnOBsJs" frameborder="0" allowfullscreen></iframe>
  103.  
  104. <p id="teacher-message">You're doing great! Keep practicing those ladders</p>
  105.  
  106. </li>
  107.  
  108. <li id="teacher-avatar">
  109. <img src="http://placehold.it/300.png/09f/fff">
  110. <h4>Mark Openheimer</h4>
  111. </li>
  112. </ul>*@
  113.  
  114. @*<ul id="student-post">
  115.  
  116. <li id="student-avatar">
  117.  
  118. <img src="http://placehold.it/300.png/09f/fff">
  119. <h4>You</h4>
  120. </li>
  121.  
  122. <li id="student-video">
  123. <iframe width="350" height="200" src="https://www.youtube.com/embed/K1LHMG__bws" frameborder="0" allowfullscreen></iframe>
  124. <p id="student-message">It feels as though I'm doing better stairway to heaven than last time. What do you think</p>
  125. </li>
  126.  
  127. </ul>*@
  128.  
  129. </div>
  130.  
  131.  
  132.  
  133. </div>
  134.  
  135. @section Scripts {
  136. <script type="text/JavaScript">
  137. $(document).ready(function () {
  138. var globalCategoryId = @ViewBag.selectedCategory;
  139. var globalTeacherId = @ViewBag.selectedTeacher;
  140. var globalLessonId = -1;
  141. var data = @(Html.Raw(Json.Encode(Model)));
  142.  
  143. $(".current-instrument").click(function (evt) {
  144. var activeId = this.id;
  145. if (activeId == globalCategoryId)
  146. return;
  147. globalCategoryId = activeId;
  148. //alert(activeId);
  149. document.getElementById("student-teacher").innerHTML = "";
  150. for (var key in data.teachers)
  151. {
  152. if (data.teachers[key].categoryId == activeId)
  153. {
  154. var teacher = data.teachers[key];
  155. document.getElementById("student-teacher").innerHTML += "<li id=" + teacher.ID + " class='current-teacher'> <img src=" + teacher.PictureUrl + "> <h4> " + teacher.FirstName + " " + teacher.LastName + "</h4> </li>";
  156. }
  157. }
  158. })
  159.  
  160. $(document).on('click', ".current-teacher", function (evt) {
  161. var activeTeacherId = this.id;
  162. //alert(activeTeacherId);
  163. if (activeTeacherId == globalTeacherId)
  164. return;
  165. globalTeacherId = activeTeacherId;
  166. document.getElementById("chat-area").innerHTML = "";
  167. // put spinner
  168. var form_data = {
  169.  
  170. teacherId: activeTeacherId,
  171. categoryId: globalCategoryId
  172. };
  173. $.ajax({
  174. type: "POST",
  175. url: "/Lesson/OneLesson",
  176. data: form_data,
  177. success: function (response) {
  178. console.log(response);
  179. if (response.ID > 0) {
  180. globalLessonId = response.ID;
  181. var chatArea = document.getElementById("chat-area");
  182. for (var key in response.messages)
  183. {
  184. var message = response.messages[key];
  185. var str = "";
  186. if (message.IsFromTeacher == true)
  187. {
  188. str += "<ul id='teacher-post'> <li id='teacher-video'>";
  189.  
  190. if (message.VideoUrl)
  191. {
  192. str += "<iframe width='350' height='200' src=" + message.VideoUrl + "frameborder='0' allowfullscreen></iframe>";
  193. }
  194. if (message.Text)
  195. {
  196. str += "<p id='teacher-message'>" + message.Text +"</p>";
  197. }
  198. str += "</li><li id='teacher-avatar'><img src=" + response.teacherPicture + "><h4>" + response.teacherName + "</h4></li></ul>"
  199. }
  200. else
  201. {
  202. str += "<ul id='student-post'><li id='student-avatar'><img src=" + response.myPicture + "><h4>You</h4></li><li id='student-video'>";
  203. if (message.VideoUrl)
  204. {
  205. str += "<iframe width='350' height='200' src=" + message.VideoUrl + "frameborder='0' allowfullscreen></iframe>";
  206. }
  207. if (message.Text)
  208. {
  209. str += "<p id='student-message'>" + message.Text +"</p>";
  210. }
  211. str += " </li></ul>"
  212. }
  213. chatArea.innerHTML += str;
  214. }
  215. }
  216. else {
  217. // show error message
  218. alert('Something went wrong. Please try again');
  219. }
  220. },
  221. error: function (xhr, ajaxOptions, thrownError) {
  222. alert(xhr.status);
  223. alert(thrownError);
  224. alert(xhr.responseText);
  225. },
  226. dataType: "json"//set to JSON
  227. })
  228.  
  229. })
  230. });
  231. </script>
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement