Source: haluview.mixin-1.0.0.js

  1. (function ($, $H) {
  2. // 名前空間を設定する
  3. let App = $H.Library;
  4. /**
  5. * データフォーマット関数
  6. * @mixin FormatMixin
  7. */
  8. App.FormatMixin = {
  9. /**
  10. * @memberof FormatMixin
  11. */
  12. formatExecute: {
  13. /**
  14. * 日付(yyyy/mm/dd)
  15. * @memberof FormatMixin
  16. */
  17. yyyySmmSdd: {
  18. format: function (value) {
  19. if (value == "" || value == null) return value;
  20. let yyyy = value.substring(0, 4);
  21. let mm = value.substring(4, 6);
  22. let dd = value.substring(6, 8);
  23. return yyyy + "/" + mm + "/" + dd;
  24. }
  25. , unformat: function (value) {
  26. if (value == "" || value == null) return value;
  27. return new String(value).replace(/\//g, "");
  28. }
  29. },
  30. /**
  31. * 日付(yyyy年mm月dd日)
  32. * @memberof FormatMixin
  33. */
  34. yyyyNmmTddH: {
  35. format: function (value) {
  36. if (value == "" || value == null) return value;
  37. let yyyy = value.substring(0, 4);
  38. let mm = value.substring(4, 6);
  39. let dd = value.substring(6, 8);
  40. return yyyy + "年" + mm + "月" + dd + "日";
  41. }
  42. , unformat: function (value) {
  43. if (value == "" || value == null) return value;
  44. let yyyy = value.substring(0, 4);
  45. let mm = value.substring(5, 7);
  46. let dd = value.substring(8, 10);
  47. return yyyy + mm + dd;
  48. }
  49. },
  50. /**
  51. * 日付(yyyy年mm月)
  52. * @memberof FormatMixin
  53. */
  54. yyyyNmmT: {
  55. format: function (value) {
  56. if (value == "" || value == null) return value;
  57. let yyyy = value.substring(0, 4);
  58. let mm = value.substring(4, 6);
  59. return yyyy + "年" + mm + "月";
  60. }
  61. , unformat: function (value) {
  62. if (value == "" || value == null) return value;
  63. let yyyy = value.substring(0, 4);
  64. let mm = value.substring(5, 7);
  65. return yyyy + mm;
  66. }
  67. },
  68. /**
  69. * 数量(カンマ)
  70. * @memberof FormatMixin
  71. */
  72. quantity: {
  73. format: function (value) {
  74. if (value == "" || value == null) return value;
  75. let formatvalue = String(value);
  76. // 符号付小数点の3桁カンマ編集対応
  77. return formatvalue.replace(/^([+-]?\d+)(?=\.|$)/, function (s) { return s.replace(/(\d+?)(?=(?:\d{3})+$)/g, '$1,'); });
  78. }
  79. , unformat: function (value) {
  80. if (value == "" || value == null) return value;
  81. return new String(value).replace(/,/g, "");
  82. }
  83. },
  84. /**
  85. * 数量(価格)
  86. * @memberof FormatMixin
  87. */
  88. price: {
  89. format: function (value) {
  90. if (value == "" || value == null) return value;
  91. let formatvalue = String(value);
  92. // 符号付小数点の3桁カンマ編集対応
  93. return formatvalue.replace(/^([+-]?\d+)(?=\.|$)/, function (s) { return s.replace(/(\d+?)(?=(?:\d{3})+$)/g, '$1,'); });
  94. }
  95. , unformat: function (value) {
  96. if (value == "" || value == null) return value;
  97. return new String(value).replace(/,/g, "");
  98. }
  99. },
  100. /**
  101. * 数量(通貨)
  102. * @memberof FormatMixin
  103. */
  104. money: {
  105. format: function (value) {
  106. if (value == "" || value == null) return value;
  107. let formatvalue = String(value);
  108. // 符号付小数点の3桁カンマ編集対応
  109. return formatvalue.replace(/^([+-]?\d+)(?=\.|$)/, function (s) { return s.replace(/(\d+?)(?=(?:\d{3})+$)/g, '$1,'); });
  110. }
  111. , unformat: function (value) {
  112. if (value == "" || value == null) return value;
  113. return new String(value).replace(/,/g, "");
  114. }
  115. }
  116. },
  117. /**
  118. * 値をフォーマットする
  119. * @memberof FormatMixin
  120. * @param {object} arg - フォーマット情報
  121. * @returns フォーマット結果
  122. */
  123. onDataFormat: function (arg) {
  124. $H.log("FormatMixin dataFormat : start");
  125. let value = arg["value"];
  126. let rule = arg["rule"];
  127. if (rule in this.formatExecute) {
  128. value = this.formatExecute[rule].format(value);
  129. }
  130. $H.log("FormatMixin dataFormat : end");
  131. return value;
  132. },
  133. /**
  134. * フォーマットを元の値に戻す
  135. * @memberof FormatMixin
  136. * @param {object} arg - フォーマット情報s
  137. * @returns 非フォーマット結果
  138. */
  139. onDataUnformat: function (arg) {
  140. $H.log("FormatMixin dataUnformat : start");
  141. let value = arg["value"];
  142. let rule = arg["rule"];
  143. if (rule in this.formatExecute) {
  144. value = this.formatExecute[rule].unformat(value);
  145. }
  146. $H.log("FormatMixin dataUnformat : end");
  147. return value;
  148. }
  149. };
  150. /**
  151. * アウトライン関数
  152. * @mixin OutlineMixin
  153. */
  154. App.OutlineMixin = {
  155. /**
  156. * ローディング画像を表示する場所を設定する
  157. * @memberof OutlineMixin
  158. */
  159. setLoadingImage: function () {
  160. let data = '<div id="loading" />';
  161. $("body").append(data);
  162. },
  163. /**
  164. * アウトラインイベントを設定し、コールバック関数を指定する
  165. * @memberof OutlineMixin
  166. * @param {object} outlineEvent - アウトラインイベント情報(未使用)
  167. */
  168. setOutlineEvent: function (outlineEvent) {
  169. $H.log("OutlineMixin setOutlineEvent : start");
  170. this.setLoadingImage();
  171. $H.log("OutlineMixin setOutlineEvent : end");
  172. }
  173. };
  174. /**
  175. * テンプレートファイル ロード関数
  176. * @mixin LoadTemplateMixin
  177. */
  178. App.LoadTemplateMixin = {
  179. /**
  180. * ナビバー テンプレート ファイルを設定する
  181. * @memberof LoadTemplateMixin
  182. * @param {object} arg - 画面情報
  183. */
  184. loadNavBar: function (arg) {
  185. $H.log("LoadTemplateMixin loadPageNavBar : start");
  186. //変数宣言
  187. let url = null;
  188. if (arg["htmlName"]) {
  189. url = $H.ApplicationURL + "/" + arg["htmlName"];
  190. $('#halu-navbar').loadTemplate(url, arg);
  191. }
  192. $H.log("LoadTemplateMixin loadPageNavBar : end");
  193. },
  194. /**
  195. * ヘッダー テンプレート ファイルを設定する
  196. * @memberof LoadTemplateMixin
  197. * @param {object} arg - 画面情報
  198. */
  199. loadHeader: function (arg) {
  200. $H.log("LoadTemplateMixin loadHeader : start");
  201. //変数宣言
  202. let url = null;
  203. if (arg["htmlName"]) {
  204. url = $H.ApplicationURL + "/" + arg["htmlName"];
  205. $('#halu-header').loadTemplate(url, arg);
  206. }
  207. $H.log("LoadTemplateMixin loadHeader : end");
  208. },
  209. /**
  210. * フッター テンプレート ファイルを設定する
  211. * @memberof LoadTemplateMixin
  212. * @param {object} arg - 画面情報
  213. */
  214. loadFooter: function (arg) {
  215. $H.log("LoadTemplateMixin loadFooter : start");
  216. //変数宣言
  217. let url = null;
  218. if (arg["htmlName"]) {
  219. url = $H.ApplicationURL + "/" + arg["htmlName"];
  220. $('#halu-footer').loadTemplate(url, arg);
  221. }
  222. $H.log("LoadTemplateMixin loadFooter : end");
  223. },
  224. /**
  225. * ページフッター テンプレート ファイルを設定する
  226. * @memberof LoadTemplateMixin
  227. * @param {object} arg - 画面情報
  228. */
  229. loadPageFooter: function (arg) {
  230. $H.log("LoadTemplateMixin loadPageFooter : start");
  231. //変数宣言
  232. let url = null;
  233. if (arg["htmlName"]) {
  234. url = $H.ApplicationURL + "/" + arg["htmlName"];
  235. $('#halu_pagefooter').loadTemplate(url, arg);
  236. }
  237. $H.log("LoadTemplateMixin loadPageFooter : end");
  238. },
  239. /**
  240. * HTMLテンプレートをロードする
  241. * @memberof LoadTemplateMixin
  242. * @param {object} arg - 画面情報
  243. */
  244. loadTemplate: function (arg) {
  245. $H.log("LoadTemplateMixin loadTemplate : start");
  246. //変数宣言
  247. let url = null;
  248. let wElement = null;
  249. let wHtmlname = null;
  250. //引数からデータを取得
  251. wElement = arg["element"];
  252. wHtmlname = arg["htmlName"];
  253. if (wElement) {
  254. if (wHtmlname) {
  255. url = $H.ApplicationURL + "/" + wHtmlname;
  256. $(wElement).loadTemplate(url, arg);
  257. }
  258. }
  259. $H.log("LoadTemplateMixin loadTemplate : end");
  260. },
  261. /**
  262. * CSSファイルを追加する
  263. * @memberof LoadTemplateMixin
  264. * @param {object} arg - 画面情報
  265. */
  266. appendCSS: function (arg) {
  267. $H.log("LoadTemplateMixin appendCSS : start");
  268. //変数宣言
  269. let url = null;
  270. if (arg["cssName"]) {
  271. url = $H.ApplicationURL + arg["cssName"];
  272. $("head").append("<link>");
  273. css = $("head").children(":last");
  274. css.attr({
  275. rel: "stylesheet",
  276. type: "text/css",
  277. href: url
  278. });
  279. }
  280. $H.log("LoadTemplateMixin appendCSS : end");
  281. }
  282. };
  283. //
  284. /**
  285. * 関数を追加する(View)
  286. * @mixin ViewMixin
  287. */
  288. App.ViewMixin = {
  289. /**
  290. * フォーカス設定時イベント
  291. * @memberof ViewMixin
  292. * @param {event} event - イベント情報
  293. * @param {object} value - 値
  294. * @param {number} focusCurRow - 現在行位置
  295. * @returns なし
  296. */
  297. onFocus: function (event, value, focusCurRow) {
  298. $H.log("ViewMixin onFocus : start");
  299. //変数宣言
  300. let target = null;
  301. let wFocusCurRow = null;
  302. let idname = null;
  303. target = event.target;
  304. switch (target.type) {
  305. case "button":
  306. break;
  307. case "checkbox":
  308. break;
  309. case "radio":
  310. break;
  311. case "file":
  312. break;
  313. case "select-one":
  314. break;
  315. case "select-multiple":
  316. break;
  317. default:
  318. target.value = value;
  319. break;
  320. }
  321. wFocusCurRow = focusCurRow;
  322. if (wFocusCurRow > 0) {
  323. wFocusCurRow = wFocusCurRow - 1;
  324. }
  325. idname = "#error" + event.target.name + wFocusCurRow;
  326. if (!$(idname)) return;
  327. $(idname).hide();
  328. $(idname).remove();
  329. $H.log("ViewMixin onFocus : end");
  330. },
  331. /**
  332. * フォーカスロスト時イベント
  333. * @memberof ViewMixin
  334. * @param {event} event - イベント情報
  335. */
  336. onBlur: function (event) {
  337. $H.log("ViewMixin onBlur : start");
  338. // 入力データをフォーマットし再表示する
  339. let target = event.target;
  340. let value = target.value;
  341. let rule = this.format[target.name];
  342. let arg = { value: value, rule: rule };
  343. switch (target.type) {
  344. case "button":
  345. break;
  346. case "checkbox":
  347. break;
  348. case "radio":
  349. break;
  350. case "file":
  351. break;
  352. case "select-one":
  353. break;
  354. case "select-multiple":
  355. break;
  356. default:
  357. value = this.onDataFormat(arg);
  358. target.value = value;
  359. break;
  360. }
  361. $H.log("ViewMixin onBlur : end");
  362. },
  363. //
  364. /**
  365. * ガイドメッセージを表示する
  366. * @memberof ViewMixin
  367. * @param {object} arg - ガイドメッセージ情報
  368. */
  369. onGuideMessage: function (arg) {
  370. $H.log("ViewMixin onGuideMessage : start");
  371. if (this.guidemessage) {
  372. $("#footer_status").html(arg["status"]);
  373. $("#footer_message").html(arg["message"]);
  374. }
  375. $H.log("ViewMixin onGuideMessage : end");
  376. },
  377. //
  378. // arg = {
  379. /**
  380. * エラーツールチップを表示する
  381. * @memberof ViewMixin
  382. * @param {object} arg - エラー情報
  383. */
  384. onErrorToolTip: function (arg) {
  385. $H.log("ViewMixin onErrorToolTip : start");
  386. let toolTip = function (target, errorText, multiline, index) {
  387. let toolTip = $("<div id='error" + target.name + index + "'></div>");
  388. $(toolTip).addClass("errorToolTip");
  389. $(target).parent().append(toolTip);
  390. let message = $("<span>" + errorText + "</span>");
  391. $(message).addClass("errorMessage");
  392. $(toolTip).append(message);
  393. }
  394. let length = arg["message"].length;
  395. let errorText = "";
  396. for (let i = 0; i < length; i++) {
  397. errorText += arg["message"][i];
  398. }
  399. toolTip(arg["target"], errorText, arg["multiline"], arg["index"]);
  400. $H.log("ViewMixin onErrorToolTip : end");
  401. },
  402. //
  403. /**
  404. * エラーツールチップを削除する
  405. * @memberof ViewMixin
  406. * @param {object} arg - イベントターゲット情報
  407. */
  408. onRemoveToolTip: function (arg) {
  409. $H.log("ViewMixin onRemoveToolTip : start");
  410. if (!$(".errorToolTip")) return;
  411. $(".errorMessage").hide();
  412. $(".errorMessage").remove();
  413. $(".errorToolTip").hide();
  414. $(".errorToolTip").remove();
  415. $H.log("ViewMixin onRemoveToolTip : end");
  416. },
  417. /**
  418. * 警告ダイアログ 初期設定
  419. * @memberof ViewMixin
  420. */
  421. initAlertDialog: function () {
  422. $H.log("ViewMixin initAlertDialog : start");
  423. let data = '<div class="modal fade" id="alertDialog" tabindex="-1" role="dialog" aria-labelledby="alertHeader" aria-hidden="true">';
  424. data += '<div class="modal-dialog">';
  425. data += '<div class="modal-content">';
  426. data += '<div class="modal-header">';
  427. data += '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
  428. data += '<h4 class="modal-title" id="alertHeader">サーバ エラー</h4>';
  429. data += '</div>';
  430. data += '<div class="modal-body" id="alertBody">';
  431. data += '<p></p></br>';
  432. data += '</div>';
  433. data += '<div class="modal-footer" id="alertFooter">'
  434. data += '<button id="alertDialogCLOSE" type="button" class="btn btn-default" data-dismiss="modal" default-value="閉じる" '
  435. data += '>閉じる</button>'
  436. data += '</div>';
  437. data += '</div>';
  438. data += '</div>';
  439. data += '</div>';
  440. $("body").append(data);
  441. $('#alertDialog').on('shown.bs.modal', function () {
  442. $("#alertDialogCLOSE").focus();
  443. })
  444. $H.log("ViewMixin initAlertDialog : end");
  445. },
  446. /**
  447. * 警告ダイアログを表示する
  448. * @memberof ViewMixin
  449. * @param {object} arg - 警告情報
  450. */
  451. onAlertDialog: function (arg) {
  452. $H.log("ViewMixin onAlertDialog : start");
  453. // タイトル・メッセージに 複数行を設定できるようにしました
  454. if (Array.isArray(arg["title"])) {
  455. $("#alertHeader").html(arg["title"].join('<br />'));
  456. } else {
  457. $("#alertHeader").text(arg["title"]);
  458. }
  459. if (Array.isArray(arg["message"])) {
  460. $("#alertBody p").html(arg["message"].join('<br />'));
  461. } else {
  462. $("#alertBody p").text(arg["message"]);
  463. }
  464. // ボタンの文字列を設定できるようにしました
  465. this.setDialogButtonLabels($("#alertFooter"), arg);
  466. $("#alertDialog").modal("show");
  467. $H.log("ViewMixin onAlertDialog : end");
  468. },
  469. /**
  470. * 確認ダイアログ 初期設定
  471. * @memberof ViewMixin
  472. * @param {object} object - ダイアログ情報
  473. */
  474. initConfirmDialog: function (object) {
  475. $H.log("ViewMixin initConfirmDialog : start");
  476. let self = object;
  477. let data = '<div id="confirmDialog" class="modal fade" tabindex="-1" role="dialog">';
  478. data += ' <div class="modal-dialog">';
  479. data += ' <div class="modal-content">';
  480. data += ' <div id="confirmHeader" class="modal-header">';
  481. data += ' <h4>確認</h4>';
  482. data += ' </div>'; // confirmHeader
  483. data += ' <div id="confirmBody" class="modal-body">';
  484. data += ' <p></p></br>';
  485. data += ' </div>'; // confirmBody
  486. data += ' <div id="confirmFooter" class="modal-footer">';
  487. data += ' <input id="confirmDialogYES" type="button" class="btn" data-dismiss="modal" aria-hidden="true" value="は い" ';
  488. data += ' default-value="は い" ';
  489. data += ' onclick="sessionStorage.setItem(\'confirmDialog\', 1);">';
  490. data += ' <input id="confirmDialogNO" type="button" class="btn" data-dismiss="modal" aria-hidden="true" value="いいえ" ';
  491. data += ' default-value="いいえ" ';
  492. data += ' onclick="sessionStorage.setItem(\'confirmDialog\', 0);">';
  493. data += ' </div>'; // confirmFooter
  494. data += ' </div>'; // confirmDialog
  495. data += ' <div>';
  496. data += '<div>';
  497. $("body").append(data);
  498. $('#confirmDialog').on('hidden.bs.modal', function () {
  499. let status = self.pubsub.publish("confirmDialogAfter");
  500. })
  501. $('#confirmDialog').on('shown.bs.modal', function () {
  502. $("#confirmDialogYES").focus();
  503. })
  504. $H.log("ViewMixin initConfirmDialog : end");
  505. },
  506. /**
  507. * 確認ダイアログを表示する
  508. * @memberof ViewMixin
  509. * @param {object} arg - ダイアログ情報
  510. */
  511. onConfirmDialog: function (arg) {
  512. $H.log("ViewMixin onConfirmDialog : start");
  513. // タイトル・メッセージ設定(複数行可)
  514. if (Array.isArray(arg["title"])) {
  515. $("#confirmHeader h4").html(arg["title"].join('<br />'));
  516. } else {
  517. $("#confirmHeader h4").text(arg["title"]);
  518. }
  519. if (Array.isArray(arg["message"])) {
  520. $("#confirmBody p").html(arg["message"].join('<br />'));
  521. } else {
  522. $("#confirmBody p").text(arg["message"]);
  523. }
  524. // ボタンの文字列を設定
  525. this.setDialogButtonLabels($("#confirmFooter"), arg);
  526. $("#confirmDialog").modal("show");
  527. $H.log("ViewMixin onConfirmDialog : end");
  528. },
  529. /**
  530. * 実行確認ダイアログ 初期設定
  531. * @memberof ViewMixin
  532. * @param {object} arg - ダイアログ情報
  533. */
  534. initExecuteDialog: function (object) {
  535. $H.log("ViewMixin initExecuteDialog : start");
  536. let self = object;
  537. let data = '<div id="executeDialog" class="modal fade" tabindex="-1" role="dialog">';
  538. data += ' <div class="modal-dialog">';
  539. data += ' <div class="modal-content">';
  540. data += ' <div id="executeHeader" class="modal-header">';
  541. data += ' <h4>実行確認</h4>';
  542. data += ' </div>'; // executeHeader
  543. data += ' <div id="executeBody" class="modal-body">';
  544. data += ' <p></p></br>';
  545. data += ' </div>'; // executeBody
  546. data += ' <div id="executeFooter" class="modal-footer">';
  547. data += ' <input id="executeDialogYES" type="button" class="btn" data-dismiss="modal" aria-hidden="true" value="は い" ';
  548. data += ' default-value="は い" ';
  549. data += ' onclick="sessionStorage.setItem(\'executeDialog\', 1);">';
  550. data += ' <input id="executeDialogNO" type="button" class="btn" data-dismiss="modal" aria-hidden="true" value="いいえ" ';
  551. data += ' default-value="いいえ" ';
  552. data += ' onclick="sessionStorage.setItem(\'executeDialog\', 0);">';
  553. data += ' </div>'; // executeFooter
  554. data += ' </div>'; // executeDialog
  555. data += ' </div>';
  556. data += '</div>';
  557. $("body").append(data);
  558. $('#executeDialog').on('hidden.bs.modal', function () {
  559. let status = self.pubsub.publish("executeDialogAfter");
  560. })
  561. $('#executeDialog').on('shown.bs.modal', function () {
  562. $("#executeDialogYES").focus();
  563. })
  564. $H.log("ViewMixin initExecuteDialog : end");
  565. },
  566. /**
  567. * 実行確認ダイアログを表示する
  568. * @memberof ViewMixin
  569. * @param {object} arg - ダイアログ情報
  570. */
  571. onExecuteDialog: function (arg) {
  572. $H.log("ViewMixin onExecuteDialog : start");
  573. // タイトル・メッセージ設定(複数行可)
  574. if (Array.isArray(arg["title"])) {
  575. $("#executeHeader h4").html(arg["title"].join('<br />'));
  576. } else {
  577. $("#executeHeader h4").text(arg["title"]);
  578. }
  579. if (Array.isArray(arg["message"])) {
  580. $("#executeBody p").html(arg["message"].join('<br />'));
  581. } else {
  582. $("#executeBody p").text(arg["message"]);
  583. }
  584. // ボタンの文字列を設定
  585. this.setDialogButtonLabels($("#executeFooter"), arg);
  586. $("#executeDialog").modal("show");
  587. $H.log("ViewMixin onExecuteDialog : end");
  588. },
  589. /**
  590. * サーバ確認ダイアログ 初期設定
  591. * @memberof ViewMixin
  592. * @param {object} object - ダイアログ情報
  593. */
  594. initServerDialog: function (object) {
  595. $H.log("ViewMixin initServerDialog : start");
  596. let self = object;
  597. let data = '<div class="modal fade" id="serverDialog" tabindex="-1" role="dialog" aria-labelledby="serverHeader" aria-hidden="true">';
  598. data += ' <div class="modal-dialog">';
  599. data += ' <div class="modal-content">';
  600. data += ' <div class="modal-header">';
  601. data += ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
  602. data += ' <div class="modal-header" id="serverHeader">';
  603. data += ' <h4>サーバ確認</h4>';
  604. data += ' </div>';
  605. data += ' </div>';
  606. data += ' <div class="modal-body" id="serverBody">';
  607. data += ' <p></p></br>';
  608. data += ' </div>';
  609. data += ' <div class="modal-footer" id="serverFooter">'
  610. data += ' <button id="serverDialogOK" type="button" class="btn btn-default" data-dismiss="modal" default-value="OK" '
  611. data += ' onclick="sessionStorage.setItem(\'serverDialog\', 1);">OK</button>'
  612. data += ' </div>';
  613. data += ' </div>';
  614. data += ' </div>';
  615. data += '</div>';
  616. $("body").append(data);
  617. $('#serverDialog').on('hidden.bs.modal', function () {
  618. let status = self.pubsub.publish("serverDialogAfter");
  619. })
  620. $('#serverDialog').on('shown.bs.modal', function () {
  621. $("#serverDialogOK").focus();
  622. })
  623. $H.log("ViewMixin initServerDialog : end");
  624. },
  625. /**
  626. * サーバ確認ダイアログを表示する
  627. * @memberof ViewMixin
  628. * @param {object} arg - ダイアログ情報
  629. */
  630. onServerDialog: function (arg) {
  631. $H.log("ViewMixin onServerDialog : start");
  632. // タイトル・メッセージ設定(複数行可)
  633. if (Array.isArray(arg["title"])) {
  634. $("#serverHeader h4").html(arg["title"].join('<br />'));
  635. } else {
  636. $("#serverHeader h4").text(arg["title"]);
  637. }
  638. if (Array.isArray(arg["message"])) {
  639. $("#serverBody p").html(arg["message"].join('<br />'));
  640. } else {
  641. $("#serverBody p").text(arg["message"]);
  642. }
  643. // ボタンの文字列を設定
  644. this.setDialogButtonLabels($("#serverFooter"), arg);
  645. $("#serverDialog").modal("show");
  646. $H.log("ViewMixin onServerDialog : end");
  647. },
  648. /**
  649. * ダイアログのボタンを設定
  650. * @memberof ViewMixin
  651. * @param {object} footerObject - フッター情報
  652. * @param {object} arg - ダイアログ情報
  653. */
  654. setDialogButtonLabels: function (footerObject, arg) {
  655. $H.log("ViewMixin setDialogButtonLabels : start");
  656. if ('button_labels' in arg) {
  657. footerObject.find('input[type="button"]').each(function (index) {
  658. $(this).val(arg.button_labels[index] !== undefined ?
  659. arg.button_labels[index] : $(this).attr('default-value'));
  660. });
  661. }
  662. $H.log("ViewMixin setDialogButtonLabels : end");
  663. },
  664. /**
  665. * セレクトボックス表示処理(IDでの設定)
  666. * @memberof ViewMixin
  667. * @param {object} defSelectBox - セレクトボックス
  668. * @param {object} responseRecord - レスポンスデータ
  669. */
  670. onShowSelectBox: function (defSelectBox, responseRecord) {
  671. $H.log("ViewMixin onShowSelectBox : start");
  672. let selectorID = defSelectBox["selectorid"];
  673. let initValue = defSelectBox["init"]["initvalue"];
  674. let initHtml = defSelectBox["init"]["inithtml"];
  675. let valueName = defSelectBox["init"]["valuename"];
  676. let htmlName = defSelectBox["init"]["htmlname"];
  677. let max = responseRecord[valueName]["value"].length;
  678. $("#" + selectorID + " option").remove();
  679. let option = $('<option selected:selected/>');
  680. if (initHtml) {
  681. option.val(initValue);
  682. option.html(initHtml);
  683. $("#" + selectorID).append(option);
  684. }
  685. for (let i = 0; i < max; i++) {
  686. option = $('<option />');
  687. option.val(responseRecord[valueName]["value"][i]);
  688. option.html(responseRecord[htmlName]["value"][i]);
  689. $("#" + selectorID).append(option);
  690. }
  691. $H.log("ViewMixin onShowSelectBox : end");
  692. },
  693. /**
  694. * セレクトボックス表示処理 IDからカレント行を一括表示する
  695. * @memberof ViewMixin
  696. * @param {object} dataSetInfo - セレクトボックス情報(データ)
  697. * @param {object} defSelectBox - セレクトボックス(画面要素)
  698. */
  699. showCurrentSelectBox: function (dataSetInfo, defSelectBox) {
  700. $H.log("View setCurrentSelectBox : start");
  701. //変数宣言
  702. let selectorid = null;
  703. let detasetID = null;
  704. let codeName = null;
  705. let dataSetRecord = null;
  706. let codeValue = null;
  707. let max = 0;
  708. max = defSelectBox.length;
  709. for (let i = 0; i < max; i++) {
  710. //初期化
  711. selectorid = null;
  712. detasetID = null;
  713. codeName = null;
  714. dataSetRecord = null;
  715. codeValue = null;
  716. //データ取得
  717. selectorid = defSelectBox[i]["selectorid"];
  718. detasetID = defSelectBox[i]["change"]["datasetid"];
  719. codeName = defSelectBox[i]["change"]["valuename"];
  720. dataSetRecord = this.appspec.getJSONChunkByIdAtRecords(dataSetInfo, detasetID);
  721. codeValue = dataSetRecord["record"][codeName]["value"][0];
  722. $("#" + selectorid).val(codeValue);
  723. }
  724. $H.log("View setCurrentSelectBox : end");
  725. },
  726. /**
  727. * チェックボックス表示処理
  728. * @memberof ViewMixin
  729. * @param {object} defCheckBox - チェックボックス
  730. * @param {object} responseRecord - レスポンスデータ
  731. */
  732. onShowCheckBox: function (defCheckBox, responseRecord) {
  733. $H.log("ViewMixin onShowCheckBox : start");
  734. //変数宣言
  735. let selectorID = null;
  736. let datasetName = null;
  737. let onValue = null;
  738. let offValue = null;
  739. //チェックボックス情報取得
  740. selectorID = defCheckBox["selectorid"]
  741. datasetName = defCheckBox["datasetname"];
  742. onValue = defCheckBox["value"]["on"];
  743. offValue = defCheckBox["value"]["off"];
  744. if (responseRecord[datasetName]["value"][0] == onValue) {
  745. $("#" + selectorID).prop("checked", true);
  746. }
  747. if (responseRecord[datasetName]["value"][0] == offValue) {
  748. $("#" + selectorID).prop("checked", false);
  749. }
  750. $H.log("ViewMixin onShowCheckBox : end");
  751. },
  752. /**
  753. * テーブル チェックボックス表示処理
  754. * @memberof ViewMixin
  755. * @param {object} defCheckBox - チェックボックス
  756. * @param {object} responseRecord - レスポンスデータ
  757. */
  758. onShowCheckBoxTable: function (defCheckBox, responseRecord) {
  759. $H.log("ViewMixin onShowCheckBoxTable : start");
  760. let selectorName = defCheckBox["selectorname"]
  761. let datasetName = defCheckBox["datasetname"];
  762. let onValue = defCheckBox["value"]["on"];
  763. let offValue = defCheckBox["value"]["off"];
  764. let max = responseRecord[datasetName]["value"].length;
  765. let targetObject = $("." + selectorName);
  766. for (let i = 0; i < max; i++) {
  767. if (responseRecord[datasetName]["value"][i] == onValue) {
  768. $(targetObject[i]).prop("checked", true);
  769. }
  770. if (responseRecord[datasetName]["value"][i] == offValue) {
  771. $(targetObject[i]).prop("checked", false);
  772. }
  773. }
  774. $H.log("ViewMixin onShowCheckBoxTable : end");
  775. },
  776. /**
  777. * ラジオボタン表示処理
  778. * @memberof ViewMixin
  779. * @param {object} defRadioButton - ラジオボタン
  780. * @param {object} responseRecord - レスポンスデータ
  781. */
  782. onShowRadioButton: function (defRadioButton, responseRecord) {
  783. $H.log("ViewMixin onShowRadioButton : start");
  784. $H.log("ViewMixin onShowRadioButton : end");
  785. },
  786. /**
  787. * JsonDataから明細テーブルを再作成する
  788. * @param {string} tableID - 明細テーブルのID
  789. * @param {object} jsonData - jsonデータ
  790. * @param {string} idName - 項目id名
  791. * @param {string} itemName - 明細テーブル項目名
  792. */
  793. recreateJsonDataToTable: function (tableID, jsonData, idName, itemName) {
  794. $H.log("ViewMixin recreateJsonDataToTable : start");
  795. // 明細テーブルの2行目移行を削除する
  796. this.deleteTableSecondRow(tableID);
  797. // 明細テーブルの1行目をクリアする
  798. let detailRecord = this.appspec.getJSONChunkByIdAtRecords(jsonData, idName)["record"];
  799. this.clearTableFirstRow(detailRecord);
  800. // 明細テーブルの1行目をデータ件数分コピーする
  801. let maxSize = detailRecord[itemName]["value"].length;
  802. this.copyTableFirstRow(tableID, maxSize);
  803. $H.log("ViewMixin recreateJsonDataToTable : end");
  804. },
  805. /**
  806. * JsonDataの値をViewに表示する<br>
  807. * (テーブルデータは対象外)
  808. * @memberof ViewMixin
  809. * @param {object} jsonData - jsonデータ
  810. */
  811. fromJsonDataToView: function (jsonData) {
  812. $H.log("ModelMixin fromJsonDataToView : start");
  813. //変数宣言
  814. let jsonRecord = null;
  815. let name = null;
  816. let object = null;
  817. let jsonRecords = null;
  818. let maxSize = null;
  819. let value = null;
  820. let rule = null;
  821. let arg = null;
  822. let tagName = null;
  823. let typeName = null;
  824. //変数宣言
  825. jsonRecords = jsonData["records"];
  826. maxSize = jsonRecords.length;
  827. for (let i = 0; i < maxSize; i++) {
  828. //初期化
  829. jsonRecord = null;
  830. //データ取得
  831. jsonRecord = jsonRecords[i];
  832. if (jsonRecord["multiline"] == "yes") {
  833. continue;
  834. }
  835. for (name in jsonRecord["record"]) {
  836. //初期化
  837. object = null;
  838. value = null;
  839. rule = null;
  840. arg = null;
  841. tagName = null;
  842. typeName = null;
  843. //データ取得
  844. object = $("#" + name)[0];
  845. if (object === undefined) {
  846. continue;
  847. }
  848. value = jsonRecord["record"][name]["value"][0];
  849. if (name in this.format) {
  850. rule = this.format[name];
  851. arg = { value: value, rule: rule };
  852. value = this.pubsub.publish("dataformat", arg);
  853. }
  854. tagName = $(object)[0].tagName;
  855. typeName = "";
  856. if (tagName == "INPUT") {
  857. typeName = $(object)[0].type;
  858. }
  859. this.setValueToObject(tagName, typeName, $(object)[0], value);
  860. }
  861. }
  862. $H.log("ModelMixin fromJsonDataToView : end");
  863. },
  864. /**
  865. * JsonDataからテーブルを再描画する
  866. * @memberof ViewMixin
  867. * @param {string} tableID - テーブルID
  868. * @param {object} jsonData - jsonデータ
  869. * @param {string} idName - id名
  870. */
  871. resetJsonDataToTable: function (tableID, jsonData, idName) {
  872. $H.log("ViewMixin resetJsonDataToTable : start");
  873. //変数宣言
  874. let detailRecord = null;
  875. let maxSize = 0;
  876. let name = null;
  877. // 明細テーブルの2行目移行を削除する
  878. this.deleteTableSecondRow(tableID);
  879. // 明細テーブルの1行目をクリアする
  880. detailRecord = this.appspec.getJSONChunkByIdAtRecords(jsonData, idName)["record"];
  881. this.clearTableFirstRow(detailRecord);
  882. // 明細行数を設定する
  883. maxSize = 0;
  884. for (name in detailRecord) {
  885. maxSize = detailRecord[name]["value"].length
  886. break;
  887. }
  888. // 明細テーブルの1行目をデータ件数分コピーする
  889. this.copyTableFirstRow(tableID, maxSize);
  890. // 明細テーブルにデータを表示する
  891. this.showJsonDataToTable(detailRecord, maxSize);
  892. $H.log("ViewMixin resetJsonDataToTable : end");
  893. },
  894. /**
  895. * テーブルの2行目以降を削除する
  896. * @param {string} tableID - テーブルid
  897. */
  898. deleteTableSecondRow: function (tableID) {
  899. $H.log("ViewMixin deleteTableSecondRow : start");
  900. $(tableID).find("tbody tr:gt(0)").remove();
  901. //変数宣言
  902. let j;
  903. let rows = null;
  904. rows = $(tableID)[0].rows;
  905. jQuery.each(rows, function (j) {
  906. let cells = rows[j].cells;
  907. jQuery.each(cells, function () {
  908. $(this).removeClass("rowBackground");
  909. });
  910. });
  911. $H.log("ViewMixin deleteTableSecondRow : end");
  912. },
  913. /**
  914. * 明細テーブルの1行目をクリアする
  915. * @memberof ViewMixin
  916. * @param {object} detailRecord - 明細データ
  917. */
  918. clearTableFirstRow: function (detailRecord) {
  919. $H.log("ViewMixin clearTableFirstRow : start");
  920. //変数宣言
  921. let name = null;
  922. let tagName = null;
  923. let typeName = null;
  924. let objArray = null;
  925. for (name in detailRecord) {
  926. //初期化
  927. objArray = null;
  928. tagName = null;
  929. typeName = null;
  930. objArray = $("." + name);
  931. if (!objArray.length) {
  932. continue;
  933. }
  934. tagName = $(objArray)[0].tagName;
  935. typeName = "";
  936. if (tagName == "INPUT") {
  937. typeName = $(objArray)[0].type;
  938. }
  939. this.setValueToObject(tagName, typeName, $(objArray)[0], "");
  940. }
  941. $H.log("ViewMixin clearTableFirstRow : end");
  942. },
  943. /**
  944. * テーブルの1行目を指定行数分コピーする
  945. * @memberof ViewMixin
  946. * @param {string} tableID - テーブルid
  947. * @param {number} maxSize - 最大行数
  948. */
  949. copyTableFirstRow: function (tableID, maxSize) {
  950. $H.log("ViewMixin copyTableFirstRow : start");
  951. //変数宣言
  952. let copySize = null;
  953. copySize = maxSize - 1;
  954. for (let i = 0; i < copySize; i++) {
  955. $(tableID + " tbody tr").eq(0).clone(true).insertAfter($(tableID + " tbody tr").eq(i));
  956. }
  957. $H.log("ViewMixin copyTableFirstRow : end");
  958. },
  959. /**
  960. * テーブルのROWにid番号を付与する
  961. * @memberof ViewMixin
  962. * @param {string} tableID - テーブルid
  963. */
  964. setRowidOfTable: function (tableID) {
  965. $H.log("ViewMixin setRowidOfTable : start");
  966. //変数宣言
  967. let table = null;
  968. let maxSize = 0;
  969. let row = null;
  970. //データ取得
  971. table = document.getElementById(tableID);
  972. maxSize = table.rows.length;
  973. for (let i = 0; i < maxSize; i++) {
  974. //初期化
  975. row = null;
  976. //データ取得
  977. row = table.rows[i];
  978. $(row).attr('id', i);
  979. }
  980. $H.log("ViewMixin setRowidOfTable : end");
  981. },
  982. /**
  983. * 明細テーブルにデータを表示する
  984. * @memberof ViewMixin
  985. * @param {object} detailRecord - 明細データ
  986. * @param {number} maxSize - 最大行数
  987. */
  988. showJsonDataToTable: function (detailRecord, maxSize) {
  989. $H.log("ViewMixin showJsonDataToTable : start");
  990. //変数宣言
  991. let name = null;
  992. let objArray = null;
  993. let tagName = null;
  994. let typeName = null;
  995. let value = null;
  996. let rule = null;
  997. let arg = null;
  998. //明細テーブルにデータを表示する
  999. for (let i = 0; i < maxSize; i++) {
  1000. for (name in detailRecord) {
  1001. //初期化
  1002. objArray = null;
  1003. tagName = null;
  1004. typeName = null;
  1005. value = null;
  1006. rule = null;
  1007. arg = null;
  1008. //項目名を取得
  1009. objArray = $("." + name);
  1010. if (!objArray.length) {
  1011. continue;
  1012. }
  1013. //タグと型を取得
  1014. tagName = $(objArray)[0].tagName;
  1015. typeName = "";
  1016. if (tagName == "INPUT") {
  1017. typeName = $(objArray)[0].type;
  1018. }
  1019. value = detailRecord[name]["value"][i];
  1020. if (name in this.format) {
  1021. rule = this.format[name];
  1022. arg = { value: value, rule: rule };
  1023. value = this.pubsub.publish("dataformat", arg);
  1024. }
  1025. this.setValueToObject(tagName, typeName, $(objArray)[i], value);
  1026. }
  1027. }
  1028. $H.log("ViewMixin showJsonDataToTable : end");
  1029. },
  1030. /**
  1031. * 画面の各オブジェクトに値をセットする
  1032. * @memberof ViewMixin
  1033. * @param {string} tagName - オブジェクト名
  1034. * @param {string} typeName - オブジェクトの種類
  1035. * @param {object} object - オブジェクト
  1036. * @param {object} value - 値
  1037. */
  1038. setValueToObject: function (tagName, typeName, object, value) {
  1039. switch (tagName) {
  1040. case "INPUT":
  1041. this.setValueToObjectOfInput(tagName, typeName, object, value);
  1042. break;
  1043. case "SELECT":
  1044. this.setValueToObjectOfInput(tagName, typeName, object, value);
  1045. break;
  1046. case "TEXTAREA":
  1047. this.setValueToObjectOfInput(tagName, typeName, object, value);
  1048. break;
  1049. default:
  1050. this.setValueToObjectOfOther(tagName, typeName, object, value);
  1051. break;
  1052. }
  1053. },
  1054. /**
  1055. * 画面の入力可能オブジェクトに値をセットする
  1056. * @memberof ViewMixin
  1057. * @param {string} tagName - オブジェクト名
  1058. * @param {string} typeName - オブジェクトの種類
  1059. * @param {object} object - オブジェクト
  1060. * @param {object} value - 値
  1061. */
  1062. setValueToObjectOfInput: function (tagName, typeName, object, value) {
  1063. switch (typeName) {
  1064. case "text":
  1065. $(object).val(value);
  1066. break;
  1067. case "checkbox":
  1068. if (value == "" || value == "0") {
  1069. $(object).prop("checked", false);
  1070. }
  1071. else {
  1072. $(object).prop("checked", true);
  1073. }
  1074. break;
  1075. case "radio":
  1076. if (value == "" || value == "0") {
  1077. $(object).prop("checked", false);
  1078. }
  1079. else {
  1080. $(object).prop("checked", true);
  1081. }
  1082. break;
  1083. case "button":
  1084. break;
  1085. default:
  1086. $(object).val(value);
  1087. break;
  1088. }
  1089. },
  1090. /**
  1091. * 画面の入力不可オブジェクトへ値を設定する
  1092. * @memberof ViewMixin
  1093. * @param {string} tagName - オブジェクト名
  1094. * @param {string} typeName - オブジェクトの種類
  1095. * @param {object} object - オブジェクト
  1096. * @param {object} value - 値
  1097. */
  1098. setValueToObjectOfOther: function (tagName, typeName, object, value) {
  1099. switch (tagName) {
  1100. case "BUTTON":
  1101. break;
  1102. case "DIV":
  1103. $(object).html(value);
  1104. break;
  1105. case "LABEL":
  1106. $(object).text(value);
  1107. break;
  1108. case "TD":
  1109. $(object).html(value);
  1110. break;
  1111. default:
  1112. $(object).html(value);
  1113. break;
  1114. }
  1115. },
  1116. // -------------------------------------------------------
  1117. // 画面遷移・選択画面 処理
  1118. // -------------------------------------------------------
  1119. /**
  1120. * 画面ヘッダ キー項目 表示&クリア処理
  1121. * @memberof ViewMixin
  1122. * @param {object} dataSet - データセット
  1123. */
  1124. setFromDatasetToViewWithSessionStorageOfHeader: function (dataSet) {
  1125. $H.log("ViewMixin setFromDatasetToViewWithSessionStorageOfHeader : start");
  1126. this.setFromDatasetToViewWithKeyInfo(dataSet, this.appspec.sessionStorageHeaderKey);
  1127. $H.log("ViewMixin setFromDatasetToViewWithSessionStorageOfHeader : end");
  1128. },
  1129. /**
  1130. * 前画面からの引き継ぎデータを表示する
  1131. * @memberof ViewMixin
  1132. * @param {object} dataSet - 引き継ぎデータ
  1133. */
  1134. setFromDatasetToViewWithBeforeStorageData: function (dataSet) {
  1135. $H.log("ViewMixin setFromDatasetToViewWithBeforeStorageData : start");
  1136. this.setFromDatasetToViewWithKeyInfo(dataSet, this.appspec.beforeStorageData);
  1137. $H.log("ViewMixin setFromDatasetToViewWithBeforeStorageData : end");
  1138. },
  1139. /**
  1140. * 画面キー情報&前画面からの引き継ぎデータを表示する
  1141. * @memberof ViewMixin
  1142. * @param {*} dataSet - 引き継ぎデータ
  1143. * @param {*} keyInfo - 画面キー情報
  1144. */
  1145. setFromDatasetToViewWithKeyInfo: function (dataSet, keyInfo) {
  1146. //変数宣言
  1147. let maxSizeKeyInfo = 0;
  1148. let datasetID = null;
  1149. let datasetRecord = null;
  1150. let maxSizeDataName = 0;
  1151. let itemName = null;
  1152. let className = null;
  1153. let typeName = null;
  1154. let strArray = null;
  1155. let $select = null;
  1156. // 検索項目をクリアする
  1157. maxSizeKeyInfo = keyInfo.length;
  1158. for (let i = 0; i < maxSizeKeyInfo; i++) {
  1159. //初期化
  1160. datasetID = null;
  1161. datasetRecord = null;
  1162. maxSizeDataName = 0;
  1163. //データ取得
  1164. datasetID = keyInfo[i]["datasetid"];
  1165. datasetRecord = this.appspec.getJSONChunkByIdAtRecords(dataSet, datasetID)["record"];
  1166. maxSizeDataName = keyInfo[i]["dataname"].length;
  1167. for (let j = 0; j < maxSizeDataName; j++) {
  1168. //初期化
  1169. itemName = null;
  1170. className = null;
  1171. typeName = null;
  1172. strArray = null;
  1173. $select = null;
  1174. //値取得
  1175. itemName = keyInfo[i]["dataname"][j];
  1176. className = keyInfo[i]["classname"][j];
  1177. typeName = keyInfo[i]["typename"][j];
  1178. if (typeName == "text") {
  1179. $("." + className).val(datasetRecord[itemName]["value"][0]);
  1180. }
  1181. if (typeName == "select") {
  1182. $("." + className).val(datasetRecord[itemName]["value"][0]);
  1183. }
  1184. if (typeName == "multipleselect") {
  1185. strArray = datasetRecord[itemName]["value"][0].split(",");
  1186. $select = $("#" + className);
  1187. $select.multipleSelect("uncheckAll");
  1188. $select.multipleSelect("setSelects", strArray);
  1189. }
  1190. if (typeName == "checkbox") {
  1191. if (datasetRecord[itemName]["value"][0] == "" || datasetRecord[itemName]["value"][0] == "0") {
  1192. $("." + className).prop("checked", false);
  1193. }
  1194. else {
  1195. $("." + className).prop("checked", true);
  1196. }
  1197. }
  1198. if (typeName == "td") {
  1199. $("." + className).text(datasetRecord[itemName]["value"][0]);
  1200. }
  1201. }
  1202. }
  1203. },
  1204. /**
  1205. * 画面が表示された時、最初にフォーカスを設定する項目を指定する
  1206. * @memberof ViewMixin
  1207. */
  1208. setFirstFocusItem: function () {
  1209. $H.log("ViewMixin setFirstFocusItem : start");
  1210. //変数宣言
  1211. let object = null;
  1212. if (this.appspec.isExists(this.appspec.firstFocusItem)) {
  1213. if (this.appspec.isExists(this.appspec.firstFocusItem[0])) {
  1214. if (this.appspec.firstFocusItem[0][0] == "class") {
  1215. object = $("." + this.appspec.firstFocusItem[0][1])[0];
  1216. }
  1217. else {
  1218. object = $("#" + this.appspec.firstFocusItem[0][1])[0];
  1219. }
  1220. object.focus();
  1221. if (object.type == "text" || object.type == "textarea") {
  1222. // キャレットを最後に設定
  1223. object.value += "";
  1224. }
  1225. }
  1226. }
  1227. $H.log("ViewMixin setFirstFocusItem : end");
  1228. },
  1229. /**
  1230. * F12押下時、フォーカスを設定する項目を指定する
  1231. * @memberof ViewMixin
  1232. */
  1233. setF12FocusItem: function () {
  1234. $H.log("ViewMixin setF12FocusItem : start");
  1235. //変数宣言
  1236. let object = null;
  1237. if (this.appspec.isExists(this.appspec.f12FocusItem)) {
  1238. if (this.appspec.isExists(this.appspec.f12FocusItem[0])) {
  1239. if (this.appspec.f12FocusItem[0][0] == "class") {
  1240. object = $("." + this.appspec.f12FocusItem[0][1])[0];
  1241. }
  1242. else {
  1243. object = $("#" + this.appspec.f12FocusItem[0][1])[0];
  1244. }
  1245. object.focus();
  1246. if (object.type == "text" || object.type == "textarea") {
  1247. // キャレットを最後に設定
  1248. object.value += "";
  1249. }
  1250. }
  1251. }
  1252. $H.log("ViewMixin setF12FocusItem : end");
  1253. }
  1254. };
  1255. }(jQuery, Halu));