dfmmalaw
4/28/2017 - 2:55 PM

Building a modal and binding properties to html

Building a modal and binding properties to html

self.saveViews = function () {
    $("#sortLoading").modal("show");

    var data = {
        selectedViewsForClient: self.selectedViewsForClient().toString(),
        volPoolIds: populateSelectedVolPoolIds().toString()
    };

    var jsonData = ko.toJSON(data);

    $.ajax({
        url: "../../japi-act/ClientView/assignViews",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        cache: false,
        data: jsonData,
        success: self.removeViews,
        error: handleEditViewsErrors
    });                        
};

self.removeViews = function () {

    var data = {
        selectedViewsForClient: self.selectedViewsAssignedToCandidateForClientUser().toString(),
        volPoolIds: populateSelectedVolPoolIds().toString()
    };

    var jsonData = ko.toJSON(data);

    $.ajax({
        url: "../../japi-act/ClientView/removeViews",
        type: "POST",
        async: false,
        contentType: "application/json; charset=utf-8",
        cache: false,
        data: jsonData,
        success: location.reload(),
        error: handleEditViewsErrors
    });
};     
<!--Edit Views Modal -->
<div class="modal fade" id="editViewsModal" tabindex="-1" role="dialog" aria-labelledby="myModal-label">
    <div class="modal-dialog modal-lg" role="document">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="closeButton" aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModal-label">Assign Views</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div id="modalWithDivider"class="col-md-6">
                        <div class="row modalRow blueText">Assign Views</div>
                        <div class="row modalRow">Select the Views you wish to <u>assign</u> to the individuals you selected on the dashboard. The assignment will not be duplicated if an individual is already assigned to a View.</div>
                        <div class="row modalRow viewDiv">
                            <select size="8" multiple class="form-control modalListbox" data-bind="options: viewsForClient, optionsValue: 'Value', optionsText: 'Text', selectedOptions: selectedViewsForClient">                                
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="row modalRow blueText">Remove Views</div>
                        <div class="row modalRow">Select the Views you wish to <u>remove</u> from the individuals you selected on the dashboard. Errors will not be generated if an individual is not assigned to the View.</div>
                        <div class="row modalRow viewDiv">
                            <select size="8" multiple class="form-control modalListbox" data-bind="options: viewsAssignedToCandidateForClientUser, optionsValue: 'Value', optionsText: 'Text', selectedOptions: selectedViewsAssignedToCandidateForClientUser">
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-primary" data-bind="enable: selectedViewsForClient().length > 0 || selectedViewsAssignedToCandidateForClientUser().length > 0, click: saveViews" data-dismiss="modal">Save</button>
            </div>
        </div>
    </div>
</div>