123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- BemsWebApplication.ReportFormat = function (params, viewInfo) {
- var formatCnt;
- var editor;
- var ReportFormatId = 0;
- var endpointSelector = "";
- if (BemsWebApplication.config.mode == "production") {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
- } else {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
- }
- var contentsUnit = 10000;
- var selectedName = null;
- //권한설정
- var hasnotModificationPermission = ko.observable(true);
- function getFormatData() {
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsReportFormat",
- },
- requireTotalCount: true,
- pageSize: 1000
- });
- dataSource.filter([
- ["parts", "=", 0]
- ]);
- dataSource.sort({ getter: "FormatName", asc: true });
- dataSource.load()
- .done(function (result) {
- for (var i = 0; i < result.length; i++) {
- if (ReportFormatId <= result[i].ReportFormatId)
- ReportFormatId = result[i].ReportFormatId;
- }
- formatCnt = result.length;
- $("#formatSelect").dxSelectBox("instance").option('dataSource', result);
- $("#formatSelect").dxSelectBox("instance").option('displayExpr', 'FormatName');
- $("#formatSelect").dxSelectBox("instance").option('valueExpr', "ReportFormatId");
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function setNewFormat() {
- if (editor == null) {
- editor = new cheditor(); // 에디터 개체를 생성합니다.
- editor.config.editorHeight = '530px'; // 에디터 세로폭입니다.
- editor.config.editorWidth = '1360px'; // 에디터 가로폭입니다.
- editor.inputForm = 'editor'; // 위에 있는 textarea의 id입니다. 주의: name 속성 이름이 아닙니다.
- editor.run(); // 에디터를 실행합니다.
- }
- else {
- editor.doCmd('NewDocument', '1');
- }
- $("#formatName").dxTextBox("instance").option('value', null);
- $("#formatName").dxTextBox("instance").option('readOnly', false);
- $("#formatTxt2").text("새 일지 양식 제목 : ");
- $("#saveBtn").dxButton("instance").option("text", "저장");
- $("#saveBtn").css("visibility", "visible");
- $("#formatName").dxTextBox("instance").option('value', null);
- $("#formatName").dxTextBox("instance").option('readOnly', false);
- $("#formatSelect").dxSelectBox("instance").option('value', null);
- getFormatData();
- }
- function saveFormat() {
- var store = new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsReportFormat",
- key: ["ReportFormatId", "parts"],
- keyType: {
- ReportFormatId: "Int32",
- parts: "Int32"
- }
- });
- var name = $("#formatName").dxTextBox("instance").option('value');
- if (!BWA.DataUtil.isValidInputValue(name)) {
- utils.toast.show('일지 이름이 정상적으로 입력되지 않았습니다 (앞뒤공백 허용안함)', 'error');
- return;
- }
- //if ($("#formatName").dxTextBox("instance").option('value') == "" || $("#formatName").dxTextBox("instance").option('value') == null) {
- // utils.toast.show('일지 이름을 입력해 주세요.', 'error');
- // return;
- //}
- var selectBoxItems = $("#formatSelect").dxSelectBox("instance").option('items');
- for (var i = 0; i < selectBoxItems.length; i++) {
- if (selectBoxItems[i].FormatName == $("#formatName").dxTextBox("instance").option('value')) {
- utils.toast.show('기존 일지 이름과 동일 합니다. 다른 이름을 적어 주세요.', 'error');
- return;
- }
- }
- var contentData = editor.outputBodyHTML();
- var partCnt = 1;
- if (contentData.length >= contentsUnit) {
- partCnt = parseInt(contentData.length / contentsUnit) + 1;
- }
- var contentsArray = new Array(partCnt);
- var contentLength = contentData.length;
- for (var i = 0; i < partCnt; i++) {
- if (contentLength <= contentsUnit) {
- contentsArray[i] = contentData;
- } else {
- if (contentLength <= contentsUnit) {
- contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit);
- } else {
- contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit);
- }
- }
- var insertData = { ReportFormatId: parseInt(ReportFormatId) + 1, FormatName: $("#formatName").dxTextBox("instance").option('value'), Content: contentsArray[i], parts: i };
- store.insert(insertData)
- .done(function (values, key) {
- utils.toast.show('일지 양식이 등록되었습니다.');
- })
- .fail(function (error) {
- utils.toast.show('일지 양식이 실패하였습니다.', 'error');
- });
- }
- $("#saveBtn").dxButton("instance").option('disabled', true);
- $("#delBtn").dxButton("instance").option('disabled', true);
- $("#newBtn").dxButton("instance").option('disabled', true);
- setTimeout(function () {
- $("#saveBtn").dxButton("instance").option('disabled', false);
- $("#delBtn").dxButton("instance").option('disabled', false);
- $("#newBtn").dxButton("instance").option('disabled', false);
- getFormatData();
- setNewFormat();
- }, 1000);
- }
- function getFormatContent() {
- $("#saveBtn").dxButton("instance").option("text", "수정");
- $("#saveBtn").css("visibility", "visible");
- editor.doCmd('NewDocument', '1');
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsReportFormat",
- },
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter([
- ["ReportFormatId", "=", $("#formatSelect").dxSelectBox("instance").option('value')]
- ]);
- dataSource.sort({ getter: "parts", asc: true });
- dataSource.load()
- .done(function (result) {
- var content = "";
- for (var i = 0; i < result.length; i++) {
- content = content + result[i].Content;
- }
- if (editor == null) {
- editor = new cheditor(); // 에디터 개체를 생성합니다.
- editor.config.editorHeight = '530px'; // 에디터 세로폭입니다.
- editor.config.editorWidth = '1360px'; // 에디터 가로폭입니다.
- editor.inputForm = 'editor'; // 위에 있는 textarea의 id입니다. 주의: name 속성 이름이 아닙니다.
- editor.run(); // 에디터를 실행합니다.
- }
- editor.insertContents(content);
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function modifyFormat() {
- var id = $("#formatSelect").dxSelectBox("instance").option('value');
- if (formatCnt == 0 || id == null) {
- utils.toast.show('일지 양식이 없습니다.', 'error');
- } else {
- var id = $("#formatSelect").dxSelectBox("instance").option('value');
- var name = $("#formatName").dxTextBox("instance").option('value');
- var selectBoxItems = $("#formatSelect").dxSelectBox("instance").option('items');
- for (var i = 0; i < selectBoxItems.length; i++) {
- if (selectBoxItems[i].FormatName == $("#formatName").dxTextBox("instance").option('value') && selectedName != name) {
- utils.toast.show('기존 일지 이름과 동일 합니다. 다른 이름을 적어 주세요.', 'error');
- return;
- }
- }
- if (!BWA.DataUtil.isValidInputValue(name)) {
- utils.toast.show('일지 이름이 정상적으로 입력되지 않았습니다 (앞뒤공백 허용안함)', 'error');
- return;
- }
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsReportFormat",
- },
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter([
- ["ReportFormatId", "=", id]
- ]);
- dataSource.load()
- .done(function (result) {
- partsCnt = result.length;
- var store = new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsReportFormat",
- key: ["ReportFormatId", "parts"],
- keyType: {
- ReportFormatId: "Int32",
- parts: "Int32"
- }
- });
- for (var i = 0; i < partsCnt; i++) {
- var removeData = { ReportFormatId: id, parts: i };
- store.remove(removeData)
- .done(function (values, key) {
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- }).fail(function (error) {
- utils.toast.show(error);
- });
- $("#saveBtn").dxButton("instance").option('disabled', true);
- $("#delBtn").dxButton("instance").option('disabled', true);
- $("#newBtn").dxButton("instance").option('disabled', true);
- setTimeout(function () {
- var store = new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsReportFormat",
- key: ["ReportFormatId"],
- keyType: {
- ReportFormatId: "Int32"
- }
- });
- var contentData = editor.outputBodyHTML();
- var partCnt = 1;
- if (contentData.length >= contentsUnit) {
- partCnt = parseInt(contentData.length / contentsUnit) + 1;
- }
- var contentsArray = new Array(partCnt);
- var contentLength = contentData.length;
- for (var i = 0; i < partCnt; i++) {
- if (contentLength <= contentsUnit) {
- contentsArray[i] = contentData;
- } else {
- if (contentLength <= contentsUnit) {
- contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit);
- } else {
- contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit);
- }
- }
- var insertData = { ReportFormatId: id, FormatName: name, Content: contentsArray[i], parts: i };
- store.insert(insertData)
- .done(function (values, key) {
- utils.toast.show('일지 양식이 수정되었습니다.');
- })
- .fail(function (error) {
- utils.toast.show('일지 양식 수정이 실패하였습니다.', 'error');
- });
- }
- setTimeout(function () {
- $("#saveBtn").dxButton("instance").option('disabled', false);
- $("#delBtn").dxButton("instance").option('disabled', false);
- $("#newBtn").dxButton("instance").option('disabled', false);
- getFormatData();
- setNewFormat();
- }, 1000);
- }, 1000);
- }
- }
- function DeleteFormat() {
- var partsCnt = 0;
- if (formatCnt == 0 || $("#formatSelect").dxSelectBox("instance").option('value') == null) {
- utils.toast.show('일지 양식이 없습니다.', 'error');
- } else {
- var id = $("#formatSelect").dxSelectBox("instance").option('value');
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsReportFormat",
- },
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter([
- ["ReportFormatId", "=", id]
- ]);
- dataSource.load()
- .done(function (result) {
- partsCnt = result.length;
- var store = new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsReportFormat",
- key: ["ReportFormatId", "parts"],
- keyType: {
- ReportFormatId: "Int32",
- parts: "Int32"
- }
- });
- for (var i = 0; i < partsCnt; i++) {
- var removeData = { ReportFormatId: id, parts: i };
- store.remove(removeData)
- .done(function (values, key) {
- utils.toast.show('일지 양식이 삭제되었습니다.');
- })
- .fail(function (error) {
- utils.toast.show('일지 양식 삭제가 실패하였습니다.', 'error');
- });
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- $("#saveBtn").dxButton("instance").option('disabled', true);
- $("#delBtn").dxButton("instance").option('disabled', true);
- $("#newBtn").dxButton("instance").option('disabled', true);
- setTimeout(function () {
- $("#saveBtn").dxButton("instance").option('disabled', false);
- $("#delBtn").dxButton("instance").option('disabled', false);
- $("#newBtn").dxButton("instance").option('disabled', false);
- getFormatData();
- setNewFormat();
- }, 1000);
- }
- }
- function handleViewShown() {
- //권한설정
- hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
- $("#delBtn").dxButton("instance").option("visible", true);
- setNewFormat();
- $SideMenu.showSideMenuIfWill(params.view);
- }
- var searchViewOptions = {
- };
- function handleSearchInSearchView() {
- }
- var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
- {
- formatSelect: {
- placeholder: "불러올 기존 일지를 선택해주세요.",
- onInitialized: function () {
- getFormatData();
- },
- onValueChanged: function () {
- if ($("#formatSelect").dxSelectBox("instance").option('value') != null) {
- $("#formatName").dxTextBox("instance").option('value', $("#formatSelect").dxSelectBox("instance").option('text'));
- $("#formatName").dxTextBox("instance").option('readOnly', false);
- $("#formatTxt2").text("기존 일지 양식 제목 : ");
- getFormatContent();
- selectedName = $("#formatSelect").dxSelectBox("instance").option('text');
- }
- }
- },
- formatName: {
- readOnly: false
- },
- newButtonClicked: function () {
- setNewFormat();
- },
- saveButtonClicked: function () {
- if ($("#saveBtn").dxButton("instance").option("text") == "저장") {
- DevExpress.ui.dialog.confirm("양식을 저장 하시겠습니까?", "저장").done(function (dialogResult) {
- if (dialogResult) {
- saveFormat();
- }
- });
- } else if ($("#saveBtn").dxButton("instance").option("text") == "수정") {
- DevExpress.ui.dialog.confirm("양식을 수정 하시겠습니까?", "수정").done(function (dialogResult) {
- if (dialogResult) {
- modifyFormat();
- }
- });
- }
- },
- delButtonClicked: function () {
- DevExpress.ui.dialog.confirm("양식을 삭제 하시겠습니까?", "삭제").done(function (dialogResult) {
- if (dialogResult) {
- DeleteFormat();
- }
- });
- },
- hasnotModificationPermission: hasnotModificationPermission //권한설정
- });
- return viewModel;
- };
|