Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. /// <reference path="../knockout/knockout-3.4.0.debug.js" />
  2. /// <reference path="../jquery/jquery.min.js" />
  3.  
  4. var deal = function () {
  5. var self = this;
  6. // These are the initial options
  7. self.ManufacturerOptions = ko.observableArray();
  8. self.VehicleManufacturerId = ko.observable();
  9. self.RangeOptions = ko.observableArray();
  10. self.VehicleRangeId = ko.observable();
  11.  
  12. var Deals = {
  13. ManufacturerOptions: self.ManufacturerOptions,
  14. VehicleManufacturerId: self.VehicleManufacturerId,
  15. RangeOptions: self.RangeOptions,
  16. VehicleRangeId: self.VehicleRangeId,
  17. };
  18.  
  19. self.Deal = ko.observable();
  20. self.Deals = ko.observableArray();
  21. RetrieveDeals();
  22. GetManufacturers();
  23.  
  24. self.EditData = function (Deal) {
  25. GetManufacturers();
  26. GetRanges(Deal.VehicleManufacturerId);
  27. self.Deal(Deal);
  28. };
  29.  
  30. function GetManufacturers() {
  31. $.ajax({
  32. url: 'http://localhost:47633/api/Vehicle/GetManufacturers',
  33. type: 'get',
  34. crossDomain: true,
  35. dataType: 'json',
  36. contentType: "application/json; charset=utf-8",
  37. success: function (dataReturned) {
  38. self.ManufacturerOptions(dataReturned);
  39. }
  40. });
  41. }
  42.  
  43. function GetRanges(manufacturerId) {
  44. $.ajax({
  45. url: 'http://localhost:47633/api/Vehicle/GetRanges?manufacturerCode=' + manufacturerId,
  46. type: 'get',
  47. crossDomain: true,
  48. dataType: 'json',
  49. contentType: "application/json; charset=utf-8",
  50. success: function (dataReturned) {
  51. self.RangeOptions(dataReturned);
  52. }
  53. });
  54. }
  55. };
  56.  
  57. $(document).ready(function () {
  58. ko.applyBindings(new deal());
  59. });
  60.  
  61. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Home.ascx.cs" Inherits="Desktop.Controls.DealBook.Home" %>
  62.  
  63. <h1>DealBook</h1>
  64. <div data-bind="if: Deal">
  65. <div>
  66. <h2>Update Deal</h2>
  67. </div>
  68. <div>
  69. <p>Manufacturer: <select id="Manufacturer" data-bind="options: ManufacturerOptions, optionsCaption: 'Select Manufacturer', optionsValue: 'cman_code', optionsText: 'cman_name', value: Deal().VehicleManufacturerId, event: { change: manufacturerChanged}"></select></p>
  70. <p>Range: <select id="Range" data-bind="options: RangeOptions, optionsCaption: 'Select Range', optionsValue: 'cran_code', optionsText: 'cran_name', value: Deal().VehicleRangeId, event: { change: rangeChanged }"></select></p>
  71. </div>
  72. <input type="button" id="btnUpdateData" class="btn btn-primary" value="Update Deal" data-bind="click: UpdateData" />
  73. <input type="button" id="btnCancel" class="btn btn-primary" value="Cancel" data-bind="click: Cancel" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement