linzhijie
2021-04-12 c632636e2f5b4188b430f5efc9d9f68c8dbe3d6d
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增产品包-job')"/>
    <th:block th:include="include :: summernote-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
 
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content body-div">
    <form class="form-horizontal m" id="form-product-add">
        <input name="multilingual" id="multilingual" type="hidden" value="">
        <div class="form-group">
            <label class="col-sm-3 control-label">[[#{jsp.exam.product.productPackageName}]]:</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">[[#{jsp.exam.product.questionnaireType}]]:</label>
            <div class="col-sm-8">
                <input class="form-control" name="levelId" id="levelId" th:value="${tExamLevel.id}" type="hidden">
                <input class="form-control" name="levelName" id="levelName" th:value="${tExamLevel.levelName}"
                       readonly="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">[[#{jsp.exam.demographyParam.languagetype}]]:</label>
            <div class="col-sm-8">
                <select name="langType" id="langType" class="form-control m-b"
                        th:with="type=${@dict.getType('lang_type')}">
                    <option value="ALL">ALL</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group input-focus" th:align="center">
            <label th:align="center" style="color: #b6151a;">( 注意:产品包指导语,内容不要直接从word复制,请务必从txt文件中复制内容 )</label>
        </div>
        <div class="form-group input-focus">
            <label class="col-sm-3 control-label">[[#{jsp.exam.product.productPackageInstructions}]]:</label>
            <div class="col-sm-8">
                <textarea name="guide" class="form-control" rows="5" cols="60"></textarea>
            </div>
        </div>
 
        <div class="form-group">
            <label class="col-sm-3 control-label">[[#{jsp.exam.productReportTemplate}]]:</label>
            <div class="col-sm-8">
                <select id="reportTemplateId" name="reportTemplateId" class="form-control noselect2 selectpicker" multiple>
                    <option th:each="dict : ${templateList}" th:text="${dict['reportType']}"
                            th:value="${dict['id']}" ></option>
                </select>
            </div>
        </div>
 
        <div id="headline">
        </div>
 
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-8">
                <button type="button" class="btn btn-w-m btn-success btn-rounded" id="addHeadline">
                    [[#{jsp.exam.product.addTopic}]]
                </button>
                <button type="button" class="btn btn-info btn-rounded add-question">
                    [[#{jsp.exam.product.titleDimensionSetting}]]
                </button>
                <button type="button" class="btn btn-w-m btn-warning" id="importQuestionsInBatches">
                    [[#{jsp.exam.product.importQuestionsInBatches}]]
                </button>
            </div>
        </div>
 
 
        <div id="addHeadline-must" style="color: red" hidden="true">*[[#{jsp.exam.product.pleaseSetATitleDimension}]]</div>
 
        <div hidden="true">
            <input name="questions" class="form-control" type="text">
        </div>
    </form>
 
    <div class="ibox-content clone" id="questionSelect" hidden="true">
        <div name="question-seq">[[#{jsp.exam.product.titleTemplate}]]</div>
        <p>[[#{jsp.exam.level.titleTemplate}]]:</p>
        <ul class="list-inline">
        </ul>
        <input type="text" hidden="true" name="contentId">
        <input type="text" hidden="true" name="questionId">
    </div>
 
    <div class="form-group clone segmentation" id="hiddenTitle" hidden="true">
        <div class="form-group">
            <label class="col-sm-3 control-label headline-index headline-index-seq">question 1 - </label>
            <div class="col-sm-9 form-inline">
                <input name="segmentationName" class="form-control must-focus" type="text"
                       style="width: 70%; margin-right: 2%;" readonly>
                <div class="segment-must" style="color: red" hidden="true">*[[#{basis.required}]]</div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label permanent-seq">[[#{jsp.exam.product.permanentNumber}]]:</label>
            <div class="col-sm-9 form-inline">
                <input name="permanentId" class="form-control must-focus" type="text"
                       style="width: 70%; margin-right: 2%;" readonly>
                <div class="segment-must" style="color: red" hidden="true">*[[#{basis.required}]]</div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label segment-discription-seq">题目1描述 - </label>
            <div class="col-sm-9 form-inline input-focus">
                <textarea name="description" class="form-control" rows="5" cols="60"
                          style="margin-top: 2%;"></textarea>
                <!--<button type="button" class="btn btn-info btn-rounded add-question">-->
                    <!--[[#{jsp.exam.product.titleDimensionSetting}]]-->
                <!--</button>-->
                <!--<button type="button" class="btn btn-info btn-rounded remove-title">-->
                    <!--[[#{jsp.exam.product.deletQeution}]]-->
                <!--</button>-->
            </div>
        </div>
        <div class="form-group segmentation-group">
            <div>
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <!--question content-->
                    <div class="ibox float-e-margins">
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name="questionId" value="">
    </div>
    <!--模态窗口-->
    <div class="modal inmodal" id="modalWindow" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-title">
                    <h5>[[#{jsp.exam.product.pleaseEnterALanguage}]]</h5>
                </div>
                <div class="modal-body" id="eg">
                    <div class="click2edit wrapper">
                        <p>[[#{jsp.exam.product.pleaseEnterQuestions}]]...</p>
                    </div>
                </div>
                <div class="modal-footer">
                    <button id="save" class="btn btn-primary  btn-xs" onclick="save()" type="button">[[#{basis.save}]]
                    </button>
                    <button id="edit" class="btn btn-danger btn-xs m-l-sm" onclick="cancel()" type="button">
                        [[#{jsp.cancel.btn}]]
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>[[#{basis.save}]]
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>[[#{basis.close}]]
        </button>
    </div>
</div>
 
<th:block th:include="include :: footer"/>
<th:block th:include="include :: summernote-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<script type="text/javascript">
    var prefix = ctx + "exam/product";
    var num = 0;
    var questionNum = 0;
    var $parent = $.operate.parentHtml();
    $('#subjectId').val($parent.$('#subjectId').val());
    $('#subjectName').val($parent.$('#subjectId option:selected').text());
 
    $("#form-product-add").validate({
        focusCleanup: true
    });
 
    function submitHandler() {
        var questionsJson = new Array();
        var $name = $('#headline').find('.headline-index');
        $($name).each(function (i) {
            var question = new Object();
            // var $headlind = $(this).parent().parent();
            var $headlind = $(this).parents('.segmentation');
            question.name = $headlind.find('[name="segmentationName"]').eq(0).val();
            question.permanentId = $headlind.find('[name="permanentId"]').eq(0).val();
            question.description = $headlind.find('[name="description"]').eq(0).val();
            question.questionItems = new Array();
            $($headlind.find('.ibox').find('[name="questionId"]')).each(function (i) {
                    var item = new Object();
                    item.id = $(this).val();
                    item.itemOrder = ++questionNum;
                    item.permanentId = question.permanentId + "-" + String.fromCharCode(i + 97);
                    question.questionItems.push(item);
                }
            );
            question.questionId = $headlind.children('[name="questionId"]').val();
            questionsJson.push(question);
        });
        $('[name="questions"]').val(JSON.stringify(questionsJson));
 
        if (!$.validate.must($('#headline'))) {
            return;
        }
 
        if (!addQuestionMust()) {
            return;
        }
 
 
        if ($.validate.form()) {
            if ($('.float-e-margins').html().trim() === "") {
                $("#addHeadline-must").removeAttrs('hidden');
                return;
            }
 
            $.operate.saveTab(prefix + "/add", $('#form-product-add').serialize());
        }
    };
 
    var edit = function (htmlValue) {
        $("#eg").addClass("no-padding");
        $('.click2edit').summernote({
            lang: 'zh-CN',
            focus: true,
            height: 120,//结合高度和disableResizeEditor的使用可以固定窗口
            //disableResizeEditor: true
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        //给富文本编辑器赋值
        $('.click2edit').summernote('code', htmlValue);
    };
 
    var addQuestionMust = function () {
        var flag = true;
        $('#headline').find('.float-e-margins').each(function () {
            if ($(this).html().trim() === "") {
                $("#addHeadline-must").removeAttrs('hidden');
                flag = false;
            }
        });
        return flag;
    };
 
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/images",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $(obj).summernote('editor.insertImage', result.url, result.fileName);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function (error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    };
 
    var save = function () {
        $("#eg").removeClass("no-padding");
        var aHTML = $('.click2edit').summernote('code');
        $('#modalWindow').modal('hide');
        var $focusInput = $('.input-focus').find('[edit="true"]');
        $focusInput.val($.trim(aHTML));
        $focusInput.removeAttrs("edit");
        $('.click2edit').summernote('destroy');
    };
 
    var cancel = function () {
        $('.input-focus').find('[edit="true"]').removeAttrs("edit");
        $('#modalWindow').modal('hide');
    };
 
    $(function () {
        var options = {
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "[[#{menu.exam.question.view}]]",
            importUrl: prefix + "/importJobData/" + $('#langType').val() + "/" + $('#levelId').val() + "/" + $('#levelName').val(),
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "product"
        };
        $.table.init(options);
 
        $('[name="langType"]').on('change', function () {
            options.importUrl = prefix + "/importJobData/" + $('#langType').val() + "/" + $('#levelId').val() + "/" + $('#levelName').val();
            $.table.init(options);
        });
 
 
        $('.body-div').on("click", "#addHeadline", function () {
            if ($.validate.form()) {
                $("#addHeadline-must").attr('hidden', 'true');
                $.modal.openTab("[[#{jsp.exam.product.pleaseSelectATopic}]]", prefix + "/addTitle/job_title" + "/" + $('#langType').val());
            }
        });
 
        $('.body-div').on("focus", ".must-focus", function () {
            $(this).siblings('div[class*="must"]').attr('hidden', 'true');
        });
 
        // add-question
        $('body').on("click", ".add-question", function () {
            if ($('#headline').html().trim() == "") {
                $.modal.alertWarning("[[#{jsp.exam.product.pleaseSelectATopic}]]");
                return;
            }
 
            if ($.validate.must($(this).parents('.segmentation'))) {
                $('#addHeadline-must').attr('hidden', 'true');
                var $thisContent = $(this).parents('.segmentation').find(".float-e-margins");
                $thisContent.attr('add-question-edit', 'true'); // add_question.html remove after save
                $.modal.openTab("[[#{jsp.exam.product.pleaseSelectATopic}]]", prefix + "/addQuestion/" + $('#levelId').val() + "/" + $('#langType').val() + "?questionTemplateId=job_title");
                $('.segmentation-group').removeAttrs("hidden");
            }
        });
 
        // 批量导入的按钮
        $('body').on("click", ".add-question-batch", function () {
            if ($.validate.must($(this).parents('.segmentation'))) {
                $('#addHeadline-must').attr('hidden', 'true');
                var $thisContent = $(this).parents('.segmentation').find(".float-e-margins");
                $thisContent.attr('add-question-edit', 'true'); // add_question.html remove after save
                $.modal.openTab("[[#{jsp.exam.product.pleaseSelectATopic}]]", prefix + "/addQuestion/" + $('#levelId').val() + "/" + $('#langType').val() + "?questionTemplateId=job_batch");
                $('.segmentation-group').removeAttrs("hidden");
            }
        });
 
        // 批量导入题目
        $('.body-div').on("click", "#importQuestionsInBatches", function () {
            if ($.validate.form()) {
                $.table.importJobExcel();
            }
        });
 
        //delet title
        $('#headline').on('click', '.remove-title', function () {
            $(this).parent().parent().parent().remove();
            $('.segment-guide-seq').each(function (i) {
                $(this).text("第" + (i + 1) + "段指导语 -");
            });
 
            $('.headline-index-seq').each(function (i) {
                $(this).text("题目" + (i + 1) + " -");
            });
 
            $('.segment-discription-seq').each(function (i) {
                $(this).text("题目" + (i + 1) + " 描述-");
                num = i + 1
            });
        });
 
        //open summernote
        $('#form-product-add').on('focus', '[name="guide"]', function () {
            $(this).attr('edit', 'true');
            edit($(this).val());
            $('#modalWindow').modal('show');
        });
 
        $('#modalWindow').on('shown.bs.modal', function () {
            var $this = $(this);
            var dialog = $this.find('.modal-dialog');
 
            // 用这种方式保持富文本编辑器的窗口向下滚动
            var scrollTop = $(document).scrollTop();
            dialog.css({
                marginTop: scrollTop - 15
            });
        });
    });
</script>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10" id="import-form">
        <div class="col-xs-offset-1">
 
            <div class="form-group  segmentation">
                <div class="form-group" hidden="true">
                    <label class="col-sm-3 control-label headline-index headline-index-seq">question1 - </label>
                    <div class="col-sm-9 form-inline">
                        <input name="segmentationName" class="form-control must-focus" type="text"
                               style="width: 70%; margin-right: 2%;" readonly>
                        <div class="segment-must" style="color: red" hidden="true">*[[#{basis.required}]]</div>
                    </div>
                </div>
                <div class="form-group" hidden="true">
                    <label class="col-sm-3 control-label permanent-seq">[[#{jsp.exam.product.permanentNumber}]]:</label>
                    <div class="col-sm-9 form-inline">
                        <input name="permanentId" class="form-control must-focus" type="text"
                               style="width: 70%; margin-right: 2%;" readonly>
                        <div class="segment-must" style="color: red" hidden="true">*[[#{basis.required}]]</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label segment-discription-seq" hidden="true">question one desc
                        - </label>
                    <div class="col-sm-9 form-inline input-focus">
                <textarea name="description" class="form-control" rows="5" cols="60"
                          style="margin-top: 2%; display: none"></textarea>
                        <button type="button" class="btn btn-warning btn-rounded add-question-batch">
                            [[#{jsp.exam.product.titleDimensionSetting}]]
                        </button>
                        <button id="import-button" type="button" onclick="display()" hidden="true">[[#{basis.import}]]
                        </button>
                    </div>
                </div>
                <div class="form-group segmentation-group">
                    <div>
                        <label class="col-sm-3 control-label"></label>
                        <div class="col-sm-8">
                            <!--question content-->
                            <div class="ibox float-e-margins ibox-dimension">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <!--<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在,更新这条数据。"> 是否更新已经存在的用户数据 &nbsp;-->
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                        class="fa fa-file-excel-o"></i> [[#{basis.template}]]</a>
            </div>
            <font color="red" class="pull-left mt10">
                [[#{jsp.exam.product.bulkImportTips}]]
            </font>
        </div>
    </form>
</script>
</body>
</html>