summaryrefslogtreecommitdiff
path: root/static/website/js/thread-user.js
blob: a8e7eeeeac9bea876761b1848c8252f6fbd67b0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
bkLib.onDomLoaded(function() {

    var questionNicEditor = new nicEditor({
        buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image'],
        iconsPath: "/static/website/js/nicEditorIcons.gif",
    });
    questionNicEditor.setPanel('questionNicPanel');
    questionNicEditor.addInstance('questionInstance');
});

$(document).ready(function() {
    /*
     * question edit section
     * set the jquery variables 
    */
    $question = $(".question");
    $question_modify = $(".question .modify");
    $question_edit = $(".question .modify .edit");
    $question_save = $(".question .modify .save");
    $questionNicPanel = $("#questionNicPanel");
    $questionInstance = $("#questionInstance");

    /* make the question editable and show modify */
    //$question.addClass("editable");
    $question_modify.show();

    /* edit and save click events */
    function modify(thisObj){
        thisObj.hide();
        thisObj.next().css("display", "block");
        $questionNicPanel.show();
        $questionInstance.focus();
    }
    $question_edit.click(function () {
        modify($question_edit);
    });
    $questionInstance.click(function() {
        modify($question_edit);
    });
    $question_save.click(function () {
        $(this).hide();
        $questionNicPanel.hide();
        $(this).prev().css("display", "block");

        /* make the ajax call */
        //var id_length = $question_save.attr("id").length;
        //var question_id = parseInt($question_save.attr("id").substr(id_length-1));
        var question_id = parseInt($question_save.data("qid"));
        console.log(question_id);
        var question_body = $questionInstance.html();
        $.ajax({
            url: "/ajax-question-update/",
            data:{
                question_id: question_id,
                question_body: question_body,
            },
            type: "POST",
            dataType: "html",
            success: function(data){
                console.log(data);
            }
        });
    });

    /*
     * reply edit section
     * set the dom variables
    */
    $reply_edit = $('.reply .edit');
    $reply_save = $(".reply .save");
    $replyPanelWrapper = $("#replyPanelWrapper");

    var replyNicEditor = new nicEditor({
        buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image'],
        iconsPath: "/static/website/js/nicEditorIcons.gif",
    });
    replyNicEditor.panelInstance('replyNicPanel');

    $reply_edit.click(function() {
        var target = $(this).data("target");
        console.log(target);
        replyNicEditor.addInstance(target);
        $(this).parents("div.reply").prepend($replyPanelWrapper);
        $replyPanelWrapper.show();
        $('#replyPanelWrapper .nicEdit-panelContain').parent().width('100%');
        $('#replyPanelWrapper .nicEdit-panelContain').parent().next().width('100%');
        $(this).hide();
        $(this).next().show();
    });

    $reply_save.click(function() {
        var target = $(this).data("target");
        replyNicEditor.removeInstance(target);
        $replyPanelWrapper.hide();
        $('#replyPanelWrapper .nicEdit-panelContain').parent().width('100%');
        $(this).hide();
        $(this).prev().show();
        
        var reply_id = parseInt($(this).data("rid"));
        var reply_body = $("#"+target).html();

        $.ajax({
            url: "/ajax-reply-update/",
            type: "POST",
            data: {
                reply_id: reply_id,
                reply_body: reply_body
            },
            success: function(data) {
                console.log(data);
            }
        });
    });
});