Projekt

Obecné

Profil

Stáhnout (2.5 KB) Statistiky
| Větev: | Revize:
1
<div id="edit-modal" class="modal fade" role="dialog">
2
    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
3
        <div class="modal-content">
4
            <div class="modal-header">
5
                <h4 class="modal-title">Navrhnout změny</h4>
6
                <button type="button" class="close" data-dismiss="modal">&times;</button>
7
            </div>
8
            <div class="modal-body">
9
                <div class="container">
10
                    <div class="row my-1" id="password-wrapper">
11
                        <div class="col-xs-12 col-sm-4">
12
                            <label for="changeIdea">Návrh změn: <b class="required">*</b></label>
13
                        </div>
14
                        <div class="col-xs-12 col-sm-8">
15
                            <textarea class="min-wdth" id="changeIdea"></textarea>
16
                        </div>
17
                    </div>
18
                </div>
19
            </div>
20
            <div class="modal-footer">
21
                <button type="button" id="submit-but" class="btn btn-default" data-dismiss="modal">Založit</button>
22
                <button type="button" class="btn btn-default" data-dismiss="modal">Zavřít</button>
23
            </div>
24
        </div>
25
    </div>
26
</div>
27

    
28
<script>
29
    $('#edit-modal').on('show.bs.modal', function (event) {
30
        const button = $(event.relatedTarget);
31
        const pseudo_id = button.data('pseudo-id');// Extract info from data-* attributes
32
        const title = button.data('title');// Extract info from data-* attributes
33

    
34
        let modal = $(this);
35

    
36
        prefill(modal);
37
        modal.find('#submit-but').click(() => createChange(modal, pseudo_id));
38

    
39
        enableSubmit(modal);
40
        modal.find("#changeIdea").change(() => enableSubmit(modal, true));
41
    });
42

    
43
    function enableSubmit(modal){
44
        if(modal.find("#changeIdea")[0].value === ""){
45
            modal.find("#submit-but").prop( "disabled", true );
46
        } else {
47
            modal.find("#submit-but").prop( "disabled", false );
48
        }
49
    }
50

    
51
    function prefill(modal, data = null){
52
        modal.find("#changeIdea").val("");
53
    }
54

    
55

    
56
    function createChange(modal, pseudo_id){
57
        const formData = new FormData();
58
        const changeIdea = modal.find("#changeIdea")[0].value;
59
        formData.append("message", changeIdea);
60
        formData.append("wordform_id", data[pseudo_id].id);
61

    
62
        var xhr = new XMLHttpRequest();
63
        xhr.open("POST", "./controller/CreateChangeRequestController.php");
64
        xhr.send(formData);
65
    }
66
</script>
(1-1/10)