Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.93 KB | None | 0 0
  1. <div id="add-edit-dialog" style="display: none" title="Add / Edit Course">
  2. <form id="add-edit-form">
  3. <div id="messageBox1">
  4. <ul></ul>
  5. </div>
  6. <fieldset>
  7. <legend></legend>
  8.  
  9. <input type="hidden" name="id" id="id" />
  10.  
  11. <table class="tableform">
  12. <tr>
  13. <td>
  14. <label for="name">Name </label>
  15. <input type="text" name="name" id="name" value="" class="text ui-widget-content ui-corner-all" />
  16. </td>
  17. <td>
  18. <label for="location">Location </label>
  19. <input type="text" name="location" id="location" value="" class="text ui-widget-content ui-corner-all" />
  20. </td>
  21. <td>
  22. <label for="category">Category </label>
  23. <input type="text" name="category" id="category" value="" class="text ui-widget-content ui-corner-all" />
  24. </td>
  25. </tr>
  26. <tr>
  27. <td colspan="3">
  28. <label for="description">Description </label>
  29. <textarea name="description" id="description" class="text ui-widget-content ui-corner-all"></textarea>
  30. </td>
  31. </tr>
  32. <tr>
  33. <td>
  34. <label for="startdate">Start Date </label>
  35. <input type="text" name="startdate" id="startdate" class="text ui-widget-content ui-corner-all" />
  36. </td>
  37. <td>
  38. <label for="enddate">End Date </label>
  39. <input type="text" name="enddate" id="enddate" class="text ui-widget-content ui-corner-all" />
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>
  44. <label for="fees">Fees </label>
  45. £ <input type="text" name="fees" id="fees" value="" class="text ui-widget-content ui-corner-all" style="width:100px" />
  46. </td>
  47. <td>
  48. <label for="totalspace">Total Space </label>
  49. <input type="text" name="totalspace" id="totalspace" value="" class="text ui-widget-content ui-corner-all" style="width:100px" />
  50.  
  51. </td>
  52. </tr>
  53. </table>
  54.  
  55. </fieldset>
  56. </form>
  57. </div>
  58.  
  59.  
  60.  
  61. <div id="tabs">
  62. <ul>
  63. <li><a href="#tabs-1">Courses</a></li>
  64. </ul>
  65. <div id="tabs-1">
  66. <div>
  67. <table id="CourseList" style="display: none"></table>
  68. </div>
  69. </div>
  70. </div>
  71.  
  72.  
  73.  
  74.  
  75.  
  76. @using (Script.Foot())
  77. {
  78.  
  79. <script type="text/javascript">
  80.  
  81. $(function () {
  82. $("#tabs").tabs();
  83. });
  84.  
  85. var CoursePost = {
  86. Id : null,
  87. Name: null,
  88. Description: null,
  89. Location: null,
  90. Category: null,
  91. StartDate: null,
  92. EndDate: null,
  93. Fees: null,
  94. TotalSpace: null,
  95. setVals: function (id,name,description,location,category,startdate,enddate,fees,totalspace) {
  96.  
  97. this.Id = id;
  98. this.Name = name;
  99. this.Description = description;
  100. this.Location = location;
  101. this.Category = category;
  102. this.StartDate = startdate;
  103. this.EndDate = enddate;
  104. this.Fees = fees;
  105. this.TotalSpace = totalspace;
  106. }
  107. };
  108.  
  109. var txtId = $("#id");
  110. var txtName = $("#name");
  111. var txtDescription = $("#description");
  112. var txtLocation = $("#location");
  113. var txtCategory = $("#category");
  114. var txtStartDate = $("#startdate");
  115. var txtEndDate = $("#enddate");
  116. var txtFees = $("#fees");
  117. var txtTotalSpace = $("#totalspace");
  118.  
  119. $(document).ready(function () {
  120. $('#CourseList').flexigrid({
  121. url: '@Url.Action("CourseList", "Course")',
  122. dataType: 'json',
  123. colModel: [
  124. {
  125. display: 'Id',
  126. name: 'Id',
  127. width: 250,
  128. sortable: true,
  129. align: 'left',
  130. hide:true
  131. },
  132. {
  133. display: 'Name',
  134. name: 'Name',
  135. width: 300,
  136. sortable: true,
  137. align: 'left'
  138. },
  139. {
  140. display: 'Description',
  141. name: 'Description',
  142. width: 180,
  143. sortable: true,
  144. align: 'left',
  145. hide:true
  146. },
  147. {
  148. display: 'Location',
  149. name: 'Location',
  150. width: 250,
  151. sortable: true,
  152. align: 'left'
  153. },
  154. {
  155. display: 'Category',
  156. name: 'Category',
  157. width: 100,
  158. sortable: true,
  159. align: 'left',
  160. },
  161. {
  162. display: 'Start Date',
  163. name: 'StartDate',
  164. width: 80,
  165. sortable: true,
  166. align: 'left'
  167. },
  168. {
  169. display: 'End Date',
  170. name: 'EndDate',
  171. width: 80,
  172. sortable: true,
  173. align: 'left'
  174. },
  175. {
  176. display: 'Fees',
  177. name: 'Fees',
  178. width: 80,
  179. sortable: true,
  180. align: 'left',
  181. hide: true
  182. },
  183. {
  184. display: 'Total Space',
  185. name: 'TotalSpace',
  186. width: 80,
  187. sortable: true,
  188. align: 'left',
  189. hide:true
  190. },
  191.  
  192. ],
  193. buttons: [{
  194. name: 'Add',
  195. bclass: 'add',
  196. onpress: test
  197. }, {
  198. name: 'Edit',
  199. bclass: 'edit',
  200. onpress: test
  201. }, {
  202. name: 'Delete',
  203. bclass: 'delete',
  204. onpress: test
  205. }, {
  206. separator: true
  207. }],
  208. searchitems: [{
  209. display: 'Name',
  210. name: 'Name'
  211. }, {
  212. display: 'Name',
  213. name: 'Name',
  214. isdefault: true
  215. }],
  216. sortname: "Name",
  217. sortorder: "asc",
  218. usepager: true,
  219. title: 'Courses',
  220. useRp: true,
  221. rp: 15,
  222. showTableToggleBtn: true,
  223. width: 900,
  224. height: 400,
  225. singleSelect: true
  226. });
  227. });
  228.  
  229. function test(com, grid) {
  230.  
  231. var selectedRows = $('.trSelected', grid).length;
  232.  
  233. if (com == 'Add') {
  234.  
  235. var $datepicker = $("#startdate");
  236. $datepicker.datepicker();
  237. $datepicker.datepicker('setDate', new Date());
  238.  
  239. var $datepicker = $("#enddate");
  240. $datepicker.datepicker();
  241. $datepicker.datepicker('setDate', new Date());
  242.  
  243. $("#add-edit-dialog").dialog("open");
  244. }
  245. if (com == 'Edit' && selectedRows > 0) {
  246. if (selectedRows == 1) {
  247.  
  248. $('.trSelected', grid).each(function () {
  249. setFormControls($('td[abbr="Id"] >div', this).html(),
  250. $('td[abbr="Name"] >div', this).html().replace(/&nbsp;/g, ''),
  251. $('td[abbr="Description"] >div', this).html(),
  252. $('td[abbr="Location"] >div', this).html().replace(/&nbsp;/g, ''),
  253. $('td[abbr="Category"] >div', this).html().replace(/&nbsp;/g, ''),
  254. $('td[abbr="StartDate"] >div', this).html(),
  255. $('td[abbr="EndDate"] >div', this).html(),
  256. $('td[abbr="Fees"] >div', this).html(),
  257. $('td[abbr="TotalSpace"] >div', this).html()
  258.  
  259. );
  260. });
  261.  
  262. $("#add-edit-dialog").dialog("open");
  263. } else {
  264. alert("Select only one row");
  265. }
  266. }
  267. else if (com == 'Delete' && selectedRows > 0) {
  268.  
  269. var proceed = confirm('Delete ' + selectedRows + ' item(s)?');
  270.  
  271. if (!proceed) {
  272. return false;
  273. }
  274.  
  275. var id;
  276.  
  277. $('.trSelected', grid).each(function (index) {
  278. id = $('td[abbr="Id"] >div', this).html();
  279. });
  280.  
  281. $.ajax({
  282. type: 'POST',
  283. data: JSON.stringify({ 'Id': id }),
  284. url: '@Url.Action("Delete", "Course")',
  285. dataType: 'json',
  286. contentType: 'application/json',
  287. success: function (result) {
  288. // insert new list into grid
  289. $('#CourseList').flexAddData(result);
  290. }
  291. });
  292.  
  293. }
  294. }
  295.  
  296. function setFormControls(id, name, description, location, category, startdate, enddate, fees, totalspace) {
  297. txtId.val(id);
  298. txtName.val(name);
  299. txtDescription.val(description);
  300. txtLocation.val(location);
  301. txtCategory.val(category);
  302. txtStartDate.val(startdate);
  303. txtEndDate.val(enddate);
  304. txtFees.val(fees);
  305. txtTotalSpace.val(totalspace);
  306. }
  307.  
  308. $("#add-edit-dialog").dialog({
  309. autoOpen: false,
  310. height: 600,
  311. width: 800,
  312. modal: true,
  313. buttons: {
  314. "Save": function () {
  315. CoursePost.setVals(txtId.val(),txtName.val(),txtDescription.val(),txtLocation.val(),txtCategory.val(),txtStartDate.val(),txtEndDate.val(),txtFees.val(),txtTotalSpace.val());
  316. $.ajax({
  317. type: 'POST',
  318. data: JSON.stringify(CoursePost),
  319. url: '@Url.Action("Save", "Course")',
  320. dataType: 'json',
  321. contentType: 'application/json',
  322. success: function (result) {
  323. // insert new list into grid
  324. $('#CourseList').flexAddData(result);
  325. }
  326. });
  327. $(this).dialog('close');
  328.  
  329. },
  330. Cancel: function () {
  331. $(this).dialog("close");
  332. }
  333. },
  334.  
  335. close: function () { setFormControls('', '', '', '',''); },
  336. open: function () {
  337. //$("#add-edit-dialog").parent().appendTo($("#add-edit-form"));
  338. }
  339.  
  340. });
  341.  
  342. $("#fees").keyup(function () {
  343. $("#fees").val(this.value.match(/[0-9]*/));
  344. });
  345.  
  346.  
  347. $("#totalspace").keyup(function () {
  348. $("#totalspace").val(this.value.match(/[0-9]*/));
  349. });
  350.  
  351.  
  352. $(function () {
  353. $("#startdate").datepicker();
  354. $("#enddate").datepicker();
  355. });
  356.  
  357. </script>
  358.  
  359. [HttpPost]
  360. public ActionResult Save(CourseRecord courserecord)
  361. {
  362.  
  363. try
  364. {
  365. if (courserecord.Id > 0)
  366. {
  367. _courseRepository.Update(courserecord);
  368.  
  369. }
  370. else
  371. {
  372. CourseRecord course = new CourseRecord()
  373. {
  374. Name = courserecord.Name,
  375. Description = courserecord.Description,
  376. Category = courserecord.Category,
  377. Location = courserecord.Location,
  378. Fees = courserecord.Fees,
  379. StartDate = courserecord.StartDate,
  380. EndDate = courserecord.EndDate,
  381. TotalSpace = courserecord.TotalSpace
  382. };
  383.  
  384. _courseRepository.Create(course);
  385. }
  386.  
  387. return CreateFlexiJson(_courseRepository.Table.OrderBy(p => p.StartDate).ToList(), 1, 1);
  388. }
  389. catch (Exception ex)
  390. {
  391. throw ex;
  392. }
  393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement