Created
January 10, 2014 11:20
-
-
Save gscattolin/8350337 to your computer and use it in GitHub Desktop.
Init function to pass the MVC server ViewModel 2 Knockout viewModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function () | |
| { | |
| require(['WorkOrderStatusConfiguration'], function (workOrderStatusConfig) | |
| { | |
| var data = $.parseJSON('@Html.Raw(Json.Encode(Model))'); | |
| workOrderStatusConfig.Init({ | |
| services: { | |
| SaveWOConfigUrl: '@Url.Action("SaveWorkOrderConfiguration", "WorkOrderStatusConfiguration")', | |
| }, | |
| bindingContainerId: 'WorkOrderStatusContainer', | |
| viewModel: ko.mapping.fromJS(data), | |
| tableHeaders: ['@Html.Localize(() => DisplayName.Created)', | |
| '@Html.Localize(() => DisplayName.InPreparation)', | |
| '@Html.Localize(() => DisplayName.Active)', | |
| '@Html.Localize(() => DisplayName.InTransit)', | |
| '@Html.Localize(() => DisplayName.Packing)', | |
| '@Html.Localize(() => DisplayName.Finished)', | |
| '@Html.Localize(() => DisplayName.Closed)'], | |
| root: $("#WorkOrderStatusContainer") | |
| }); | |
| }); | |
| }); | |
| var saveChange = function () { | |
| $.blockUI(); | |
| $.ajax( | |
| { | |
| cache: false, | |
| dataType: 'json', | |
| type: "POST", | |
| contentType: 'application/json', | |
| url: self.services.SaveWOConfigUrl, | |
| data: JSON.stringify(ko.mapping.toJS(self.viewModel)), | |
| success: function (data) { | |
| if (!data.Success) { | |
| toastr.error(data.Message); | |
| } else { | |
| toastr.success(data.Message); | |
| } | |
| $.unblockUI(); | |
| }, | |
| error: function (data) { | |
| toastr.error(data); | |
| } | |
| }).done( | |
| function () { | |
| $.unblockUI(); | |
| } | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment