var $ = require("jquery"); var app = require("app"); var Backbone = require("backbone"); var _ = require('underscore'); /* ------------------------------------------ PlusMinusRow.js Start ------------------------------------------ */ var PlusMinusRow = function (options) { // 사용자가 정의하지 않은 일부 옵션 변수의 기본값 var defaults = { maxRow: 0, // 행 추가 최대 개수 (0: 무제한) copyRowNoSize: 1 // 행 순번(No) 증가량 }; // 사용자가 정의할 수 있는 옵션 변수 var options = { tableId: options.tableId, // 행 추가/삭제 수행 테이블 id (*필수) plusBtnId: options.plusBtnId, // 행 추가 버튼 id (*필수) minusBtnId: options.minusBtnId, // 행 삭제 버튼 id (*필수) copyRowClass: options.copyRowClass, // 복사할 행(tr)의 class (*필수) copyRowNoClass: options.copyRowNoClass, // 순번(No) 열(td)의 class copyRowNoSize: options.copyRowNoSize, // 순번(No) 증가량 :int rowNo: options.rowNo, // 입력한 행 수만큼 추가 maxRow: options.maxRow, // 행 추가 최대 개수 :int maxNo: options.maxNo, // 행 추가 최대 순번(No) :int rowspanClass: options.rowspanClass, // 처리할 rowspan 속성이 있는 열(td)의 class plusRowCallback: options.plusRowCallback, // 행 추가 콜백 함수명 minusRowCallback: options.minusRowCallback // 행 삭제 콜백 함수명 }; var settings = $.extend({}, defaults, options); // 행 추가 수행 횟수 계산 (순번 계산시 필요) - 문서 수정하는 경우 고려 var plusCnt; if ($("#" + settings.tableId + " .copiedRow")[0] === undefined) { plusCnt = 1; } else { // 다중행일 경우 고려 if (!$($("#" + settings.tableId + " ." + settings.copyRowClass + " td")[0]).attr("rowspan")) { plusCnt = $("#" + settings.tableId + " .copiedRow").length + 1; } else { var rowCnt = parseInt($($("#" + settings.tableId + " ." + settings.copyRowClass + " td")[0]).attr("rowspan")); plusCnt = ($("#" + settings.tableId + " .copiedRow").length + rowCnt) / rowCnt; } } //입력한 행 수만큼 추가 $("." + settings.rowNo).on('change', function () { $("#" + settings.tableId + " .copiedRow").remove(); plusCnt=1; var row_no = parseInt($("." + settings.rowNo+ " input").val()); for(var i=0; i -1) && !(componentType.search("radio") > -1)) { var newId = settings.tableId+"_"+($("#" + settings.tableId).find(".copiedRow").length + i) + "_" + editorFormCnt; $(v).attr({name: newId, id: newId}); $(v).val(""); // currency 초기화 if (componentType.search("currency") > -1) { var parseKey; componentType.replace(/{{([^}}]*)}}/g, function (m, key) { parseKey = key; }); var precision = parseKey.split('_'); $(v).inputmask({ 'alias': 'decimal', 'groupSeparator': ',', 'autoGroup': true, 'digits': parseInt(precision[1] ? precision[1] : '0'), // 소수점 처리 (ex. {{currency_3}}일 때) 'allowMinus': true }); } // calendar 초기화 else if (componentType.search("calendar") > -1) { $(v).datepicker("destroy").removeClass('hasDatepicker'); $(v).datepicker({ dateFormat: "yy-mm-dd(D)", changeMonth: true, changeYear: true, yearSuffix: "", }); } } // radio 초기화 - 기본 형식 고려: {{radio_A_B ...}} → editorForm_0_A, editorForm_0_B, ... else if (componentType.search("radio") > -1) { if ($(v).attr('name') == radioName) { editorFormCnt--; } else { radioName = $(v).attr('name'); } var newName = settings.tableId+"_"+($("#" + settings.tableId).find(".copiedRow").length + i) + "_" + editorFormCnt; var newId = settings.tableId+"_"+($("#" + settings.tableId).find(".copiedRow").length + i) + "_" + editorFormCnt + "_" + componentId.split("_")[2]; $(v).attr({name: newName, id: newId, checked: false}); } // check 초기화 - 기본 형식 고려: {{check_A_B ...}} → editorForm_1_A, editorForm_1_B, ... else if (componentType.search("check") > -1) { var curCheckName = $(v).attr('name').split("_")[0] + "_" + $(v).attr('name').split("_")[1]; if (curCheckName == checkName) { editorFormCnt--; } else { checkName = curCheckName; } var newId = settings.tableId+"_"+($("#" + settings.tableId).find(".copiedRow").length + i) + "_" + editorFormCnt + "_" + componentId.split("_")[2]; $(v).attr({name: newId, id: newId, checked: false}); } editorFormCnt++; }); // select 초기화 $.each($tr.find("td select"), function (k, v) { var componentName = $(v).attr("name"); // 기본 형식에서 id 속성이 존재하지 않으므로 name 값을 가져옴 var newName = settings.tableId+"_"+($("#" + settings.tableId).find(".copiedRow").length + i) + "_" + editorFormCnt; $(v).attr({name: newName, id: newName}); editorFormCnt++; }); // textarea 초기화 $.each($tr.find("td textarea"), function (k, v) { var componentId = $(v).attr("id"); var newId = settings.tableId+"_"+($("#" + settings.tableId).find(".copiedRow").length + i) + "_" + editorFormCnt; $(v).attr({name: newId, id: newId}); $(v).val(""); editorFormCnt++; }); // TODO : cOrg 초기화 // TODO : cSum, rSum 초기화 return $tr; } function minusRow() { // 추가된 행(copiedRow)이 존재하면 if ($("#" + settings.tableId + " .copiedRow")[0] !== undefined) { // ① rowspan 처리 후 (optional) if ($("#" + settings.tableId + " ." + settings.rowspanClass)[0] !== undefined) { $.each($("#" + settings.tableId + " ." + settings.rowspanClass), function (k, v) { $(v).attr("rowspan", parseInt($(v).attr("rowspan")) - $("#" + settings.tableId + " ." + settings.copyRowClass).length); }); } // ① 마지막 행(copiedRow) 삭제 for (var i = 0; i < $('.' + settings.copyRowClass).length; i++) { $("#" + settings.tableId + " .copiedRow:last").remove(); } plusCnt--; } // ② 행 삭제 콜백 함수 실행 if (typeof settings.minusRowCallback == 'function') { settings.minusRowCallback(this); } } }; var Integration = Backbone.View.extend({ initialize : function(options){ this.options = options || {}; this.docModel = this.options.docModel; this.variables = this.options.variables; this.infoData = this.options.infoData; }, render : function() { var self = this; $('.viewModeHiddenPart').show(); PlusMinusRow({ //행 추가/삭제 tableId : "dynamic_table1", plusBtnId : "plus1", minusBtnId : "minus1", copyRowClass : "copyRow1", rowspanClass : "rowspanTd1" }); PlusMinusRow({ //행 추가/삭제 tableId : "dynamic_table2", plusBtnId : "plus2", minusBtnId : "minus2", copyRowClass : "copyRow2", rowspanClass : "rowspanTd2" }); PlusMinusRow({ //행 추가/삭제 tableId : "dynamic_table3", plusBtnId : "plus3", minusBtnId : "minus3", copyRowClass : "copyRow3", rowspanClass : "rowspanTd3" }); }, renderViewMode : function(){$('.viewModeHiddenPart').hide();}, onEditDocument : function(){this.render();}, beforeSave :function() {$('.viewModeHiddenPart').hide();}, afterSave :function() {$('.viewModeHiddenPart').hide();}, validate :function() {return true;}, getDocVariables : function(){} }); return Integration;