PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/SberbankAuditSUP/HTML/my.js

https://github.com/chaojidashuaige/atc-sber-audit
JavaScript | 1320 lines | 1013 code | 196 blank | 111 comment | 266 complexity | 42a3bad7c0ac4c38fbf1ceeaebd15a96 MD5 | raw file
  1. $(function() {
  2. });
  3. var $template;
  4. var $previousData;
  5. var $storedAnswers;
  6. var $previousAnswers;
  7. var taskId;
  8. var vizitType;
  9. var targetPercent;
  10. var previousValue;
  11. var $reduceIndexes;
  12. var $activities;
  13. var questionMap;
  14. var questionPanelMap;
  15. var questionGroupMap;
  16. var dependentMap;
  17. var blockMap;
  18. var answersChanged;
  19. /******************************************************************************
  20. * Description:
  21. * Return:
  22. *****************************************************************************/
  23. function LoadCL(templateXml, previousDataXml, readOnly) {
  24. if ((templateXml === 0) || (templateXml.length === 0)) {
  25. return;
  26. }
  27. var QA = $($.parseXML(templateXml));
  28. //var start = new Date().getTime();
  29. /*
  30. var $leftPanel = $.createHtmlElement("div").attr("id", "leftPanel").addClass("leftPanel");
  31. var $rightPanel = $.createHtmlElement("div").attr("id", "rightPanel").addClass("rightPanelContent");
  32. */
  33. /*var $root = */$("#checklistForm\\:checklistBody").html(
  34. $.createHtmlElement("root").append(
  35. $.createHtmlElement("div").addClass("rightPanel").append(
  36. $.createHtmlElement("div").addClass("rightPanelFull").append(
  37. $.createHtmlElement("div").addClass("ResultsPanel").append(
  38. $.createHtmlElement("table").attr("id", "metricTable")
  39. )
  40. ).append(
  41. /*$rightPanel*/$.createHtmlElement("div").attr("id", "rightPanel").addClass("rightPanelContent").append(
  42. $.createHtmlElement("a").attr("name", "top")
  43. )
  44. )
  45. )
  46. ).append(
  47. /*$leftPanel*/$.createHtmlElement("div").attr("id", "leftPanel").addClass("leftPanel")
  48. ).append(
  49. $.createHtmlElement("div").css({ "clear" : "both", "height" : "1px" }).html(" ")
  50. ).html()
  51. );
  52. var $leftPanel = $("#leftPanel");
  53. var $rightPanel = $("#rightPanel");
  54. var previousDataXmlDoc = $($.parseXML(previousDataXml));
  55. $previousData = $(previousDataXmlDoc).children("initialData");
  56. $storedAnswers = $previousData.children("storedAnswers").children("answer");
  57. $previousAnswers = $previousData.children("previousAnswers").children("answer");
  58. $template = $(QA).children("template");
  59. var mvsAreaFlag = $previousData.attr("mvsAreaFlag");
  60. var employeeTbSubbranch = $previousData.attr("employeeTbSubbranch");
  61. taskId = $previousData.attr("taskId");
  62. vizitType = $previousData.attr("visitType");
  63. targetPercent = $previousData.attr("targetPercent");
  64. previousValue = $previousData.attr("previousValue");
  65. $reduceIndexes = $previousData.find("reduceIndex");
  66. $activities = $previousData.children("activities").children("activity");
  67. answersChanged = false;
  68. questionMap = {};
  69. questionPanelMap = {};
  70. questionGroupMap = {};
  71. dependentMap = {};
  72. blockMap = {};
  73. if ((vizitType === "VT_SELF") || (vizitType === "VT_AUDIT") || (vizitType === "VT_GEMBA")) {
  74. var $inspectionFormats = $previousData.children("inspectionFormats").children("inspectionFormat").filter(function(index) {
  75. return $template.find("question inspectionFormat[id = '" + $(this).attr("id") + "']").attr("id") != null;
  76. });
  77. if ($inspectionFormats.length > 0) {
  78. var $inspectionFormatsGroup = $.createHtmlElement("div").attr("id", "inspectionFormatsGroup")
  79. .css({ "max-height" : "150px", "overflow-y" : "auto" })
  80. .append($.createHtmlElement("p").addClass("menuFilterCaption").text("Фильтр: Форматы проверки: "));
  81. $inspectionFormats.each(function() {
  82. var key = $(this).attr("key");
  83. $inspectionFormatsGroup.append(
  84. $.createHtmlElement("p").addClass("menuFilter").append(
  85. $.createHtmlElement("input")
  86. .attr("id", key)
  87. .attr("name", "inspectionFormatsGroup")
  88. .attr("type", "checkbox")
  89. .removeAttr("checked")
  90. .change(showQuestions)
  91. ).append(
  92. $.createHtmlElement("label").attr("for", key).text($(this).attr("name"))
  93. )
  94. );
  95. });
  96. $leftPanel.append($inspectionFormatsGroup);
  97. }
  98. if ((vizitType === "VT_AUDIT") || (vizitType === "VT_GEMBA")) {
  99. var $showOptionsGroup = $.createHtmlElement("div").attr("id", "showOptionsGroup")
  100. .append($.createHtmlElement("p").addClass("menuFilterCaption").text("Опции показа: "));
  101. $previousData.children("showOptions").children("showOption").each(function() {
  102. var key = $(this).attr("key");
  103. $showOptionsGroup.append(
  104. $.createHtmlElement("p").addClass("menuFilter").append(
  105. $.createHtmlElement("input")
  106. .attr("id", key)
  107. .attr("name", "showOptionsGroup")
  108. .attr("type", "radio")
  109. .removeAttr("checked")
  110. .change(showQuestions)
  111. ).append(
  112. $.createHtmlElement("label").attr("for", key).text($(this).attr("name"))
  113. )
  114. );
  115. });
  116. $showOptionsGroup.find("input").filter(":first").attr("checked", "checked");
  117. $leftPanel.append($showOptionsGroup);
  118. }
  119. }
  120. //var time = 0;
  121. $template.children("blocks").children("block").each(function() {
  122. var $block = $(this);
  123. var blockId = $block.attr("id");
  124. var blockElementId = "odcl-bl-" + blockId;
  125. var subbranchId = $block.children("subbranch").attr("id");
  126. var levelKey = $block.children("subbranch").children("level").attr("key");
  127. if (!((levelKey === "SL_CA") || (levelKey === "SL_TB") && (subbranchId === employeeTbSubbranch))) {
  128. return; // continue
  129. }
  130. if ((mvsAreaFlag != null) && (mvsAreaFlag === "false")) {
  131. if ($block.find("question metric").filter("[key ^= 'M_MVS_']").size() > 0) {
  132. return; // continue
  133. }
  134. }
  135. blockMap[blockId] = $block;
  136. $leftPanel.append($.createHtmlElement("div")
  137. .attr("id", blockElementId)
  138. .addClass("menuBlock menuGroup od-collapse")
  139. .text($block.attr("name")));
  140. // Контейнер групп
  141. $menuGroup = $.createHtmlElement("div")
  142. .attr("id", blockElementId + "-cnt")
  143. .addClass("od-hidden ID" + blockElementId);
  144. var $blockMetrics = $block.children("metrics").children("metric");
  145. $blockMetrics.attr("max", 0.0);
  146. $blockMetrics.attr("value", 0.0);
  147. $block.children("groups").children("group").each(function() {
  148. var $group = $(this);
  149. var groupId = $group.attr("id");
  150. var groupElementId = blockElementId + "-gr-" + groupId;
  151. $blockMetrics.each(function() {
  152. var $metric = $(this);
  153. var metricKey = $metric.attr("key");
  154. if ((metricKey === "M_QUALITY") || (metricKey === "M_MVS_QUALITY")) {
  155. $group.attr("m-" + $metric.attr("id") + "-max", 0.0);
  156. }
  157. });
  158. $menuGroup.append($.createHtmlElement("div")
  159. .attr("id", groupElementId)
  160. .addClass("menuGroup menu-sub")
  161. .text($group.attr("name")));
  162. $group.children("questions").children("question").each(function() {
  163. var $question = $(this);
  164. var questionId = $question.attr("id");
  165. var questionElementId = groupElementId + "-q-" + questionId;
  166. var $questionMetrics = $question.children("questionMetrics");
  167. var hasResultMetric = false;
  168. questionMap[questionId] = $question;
  169. questionGroupMap[questionId] = groupId;
  170. //var start = new Date().getTime();
  171. $blockMetrics.each(function() {
  172. var $metric = $(this);
  173. var metricId = $metric.attr("id");
  174. var metricKey = $metric.attr("key");
  175. var points = $questionMetrics.find("metric[id = '" + metricId + "']").attr("max");
  176. if (points != null) {
  177. if (metricKey === "M_RESULT") {
  178. $metric.attr("max", parseFloat($metric.attr("max")) + parseFloat(points));
  179. hasResultMetric = true;
  180. } else if ((metricKey === "M_QUALITY_CHECKUP")
  181. || (metricKey === "M_STANDARDS") || (metricKey === "M_MVS_STANDARDS")
  182. || (metricKey === "M_SALES_TECH") || (metricKey === "M_MVS_SALES_TECH")
  183. || (metricKey === "M_KNOWLEDGE") || (metricKey === "M_MVS_KNOWLEDGE")) {
  184. $metric.attr("max", parseFloat($metric.attr("max")) + parseFloat(points));
  185. } else if ((metricKey === "M_QUALITY") || (metricKey === "M_MVS_QUALITY")) {
  186. var groupMetricAttr = "m-" + metricId + "-max";
  187. $group.attr(groupMetricAttr, parseFloat($group.attr(groupMetricAttr)) + parseFloat(points));
  188. }
  189. }
  190. });
  191. //time += (new Date().getTime() - start);
  192. var $questionElement = $.createHtmlElement("div")
  193. .attr("id", questionElementId)
  194. .addClass("QuestionPanel ID" + groupElementId);
  195. var $questionAnswerField = $.createHtmlElement("div").addClass("question_result").css("align", "center");
  196. var $buttonField = $.createHtmlElement("div").addClass("buttonActivityContainer");
  197. var $activityInfoField = $.createHtmlElement("div");
  198. var $questionActivities = $activities.filter("[questionId = '" + questionId + "']");
  199. if ($questionActivities.size() > 0) {
  200. $activityInfoField.append($.createHtmlElement("p").text("Мероприятия: "));
  201. var $activityList = $.createHtmlElement("ul").addClass("activityList");
  202. $questionActivities.each(function() {
  203. var text = $(this).attr("name") + " (до " + $(this).attr("dueDate") + ")";
  204. $activityList.append($.createHtmlElement("li").append($.createActivityLink($(this).attr("id"), text)));
  205. });
  206. $activityInfoField.append($activityList);
  207. }
  208. var dependOnId = $question.attr("dependOnId");
  209. if (dependOnId != null) {
  210. $questionElement.addClass("dependent");
  211. if (typeof dependentMap[dependOnId] === "undefined") {
  212. dependentMap[dependOnId] = [];
  213. }
  214. dependentMap[dependOnId].push({ "id" : questionId, "itemId" : $question.children("dependOnItem").attr("id") });
  215. }
  216. var $maxPoints = null;
  217. if (hasResultMetric) {
  218. var points = $questionMetrics.find("metric[key = 'M_RESULT']").attr("max");
  219. if (points > 0) {
  220. $maxPoints = $.createHtmlElement("div").css('float', 'right').html("Вес вопроса: " + addPointText(points));
  221. }
  222. }
  223. $questionElement.append(
  224. $.createHtmlElement("table").append(
  225. $.createHtmlElement("tr").append(
  226. $.createHtmlElement("td").attr("width", "60%").append(
  227. $.createHtmlElement("div")
  228. .addClass("question")
  229. .html($question.attr("number") + ". " + $question.children("text").text() +
  230. ((vizitType !== "VT_GEMBA") && ($question.attr("mandatory") === "true") ||
  231. (vizitType === "VT_GEMBA") && ($question.attr("mandatoryManagement") === "true")
  232. ? " (*)" : ""))
  233. ).append(
  234. $.createHtmlElement("div")
  235. .addClass("question_desc")
  236. .html($question.children("desc").text())
  237. )
  238. ).append(
  239. $.createHtmlElement("td").addClass("splitter")
  240. ).append(
  241. $.createHtmlElement("td").attr("width", "40%")
  242. .append($maxPoints)
  243. .append($questionAnswerField)
  244. .append($buttonField)
  245. .append($activityInfoField)
  246. )
  247. )
  248. );
  249. var answerType = $question.children("answerType").attr("key");
  250. var $storedAnswer = $storedAnswers.filter("[questionId = '" + questionId + "']");
  251. var $previousAnswer = $previousAnswers.filter("[questionId = '" + questionId + "']");
  252. $question.attr("answerId", $storedAnswer.attr("id"));
  253. if (answerType === "AT_STRING") {
  254. var $stringElement = $.createHtmlElement("input")
  255. .attr("name", questionElementId)
  256. .attr("type", "text")
  257. .attr("maxlength", "2000")
  258. .val($storedAnswer.children("stringValue").text())
  259. .change(function() {
  260. answersChanged = true;
  261. });
  262. if ($question.attr("answerMask") != null) {
  263. $stringElement.mask($question.attr("answerMask"));
  264. }
  265. if (readOnly && (taskId != null)) {
  266. $stringElement.attr("disabled", true);
  267. }
  268. $questionAnswerField.append($stringElement);
  269. } else if (answerType === "AT_NUMERIC") {
  270. var $numericElement = $.createHtmlElement("input")
  271. .attr("name", questionElementId)
  272. .attr("type", "text")
  273. .attr("maxlength", "15")
  274. .val($storedAnswer.children("numberValue").text())
  275. .numeric({ decimal : "," })
  276. .change(function() {
  277. answersChanged = true;
  278. countMetrics();
  279. });
  280. if (readOnly && (taskId != null)) {
  281. $numericElement.attr("disabled", true);
  282. }
  283. $questionAnswerField.append($numericElement);
  284. } else if (answerType === "AT_DATE") {
  285. var $dateElement = $.createHtmlElement("input")
  286. .attr("name", questionElementId)
  287. .attr("type", "text")
  288. .val($storedAnswer.children("dateValue").text())
  289. .mask("99.99.9999")
  290. .change(function() {
  291. answersChanged = true;
  292. });
  293. if (readOnly && (taskId != null)) {
  294. $dateElement.attr("disabled", true);
  295. }
  296. $questionAnswerField.append($dateElement);
  297. $questionAnswerField.append(
  298. $.createHtmlElement("table").append(
  299. $.createHtmlElement("tr").append(
  300. $.createHtmlElement("td").append($dateElement)
  301. )
  302. ).append(
  303. $.createHtmlElement("tr").append(
  304. $.createHtmlElement("td").addClass("question_desc").text("Поддерживаемый шаблон: ДД.ММ.ГГГГ")
  305. )
  306. )
  307. );
  308. } else if (answerType === "AT_MEMO") {
  309. var $memoElement = $.createHtmlElement("textarea")
  310. .attr("cols", "40").attr("rows", "10")
  311. .attr("name", questionElementId)
  312. .attr("maxlength", "2000")
  313. .val($storedAnswer.children("stringValue").text())
  314. .change(function() {
  315. answersChanged = true;
  316. });
  317. if (readOnly && (taskId != null)) {
  318. $memoElement.attr("disabled", true);
  319. }
  320. $questionAnswerField.append($memoElement);
  321. } else if (answerType === "AT_DDLIST-ONE") {
  322. var storedItemId = $storedAnswer.children("items").children("item").attr("id");
  323. var previousItemId = $previousAnswer.children("items").children("item").attr("id");
  324. var $selectElement = $.createHtmlElement("select")
  325. .attr("name", questionElementId)
  326. .change(function() {
  327. answersChanged = true;
  328. countMetrics();
  329. })
  330. .change({ "question" : $question, "questionId" : questionId }, showDependencies);
  331. $question.children("dic").children("items").children("item").each(function() {
  332. var $item = $(this);
  333. var itemId = $item.attr("id");
  334. var itemName = $item.attr("name");
  335. var answerItemId = questionElementId + "_" + itemId;
  336. var $optionElement = $.createHtmlElement("option")
  337. .attr("id", answerItemId)
  338. .val(itemName).text(itemName);
  339. if (itemId === storedItemId) {
  340. $optionElement.attr("selected", "selected");
  341. } else {
  342. $optionElement.removeAttr("selected");
  343. }
  344. if (itemId === previousItemId) {
  345. $optionElement.css("font-weight", "bold");
  346. }
  347. if (readOnly && (taskId != null)) {
  348. $optionElement.attr("disabled", true);
  349. }
  350. $selectElement.append($optionElement);
  351. });
  352. if (($selectElement.find("option").val() != null) && ($selectElement.find(":selected").val() == null)) {
  353. $selectElement.find("option:first").attr("selected", "selected");
  354. }
  355. $questionAnswerField.append($selectElement);
  356. } else if (answerType === "AT_CHECKLIST") {
  357. var $items = $question.children("dic").children("items").children("item");
  358. var $storedItems = $storedAnswer.children("items").children("item");
  359. var $previousItems = $previousAnswer.children("items").children("item");
  360. $items.each(function() {
  361. var $item = $(this);
  362. var itemId = $item.attr("id");
  363. var answerItemId = questionElementId + "_" + itemId;
  364. var $checkboxElement = $.createHtmlElement("input")
  365. .attr("id", answerItemId)
  366. .attr("name", questionElementId)
  367. .attr("type", "checkbox")
  368. .change(function() {
  369. answersChanged = true;
  370. countMetrics();
  371. })
  372. .change({ "question" : $question, "questionId" : questionId }, showDependencies);
  373. if ($storedItems.filter("[id = '" + itemId + "']").size() === 1) {
  374. $checkboxElement.attr("checked", "checked");
  375. } else {
  376. $checkboxElement.removeAttr("checked");
  377. }
  378. if (readOnly && (taskId != null)) {
  379. $checkboxElement.attr("disabled", true);
  380. }
  381. var $checkboxElementLabel = $.createHtmlElement("label")
  382. .attr("for", answerItemId)
  383. .text($item.attr("name"));
  384. if ($previousItems.filter("[id = '" + itemId + "']").size() === 1) {
  385. $checkboxElement.css("font-weight", "bold");
  386. }
  387. $questionAnswerField.append($.createHtmlElement("p").append($checkboxElement).append($checkboxElementLabel));
  388. });
  389. } else if (answerType === "AT_RADIO") {
  390. var $items = $question.children("dic").children("items").children("item");
  391. var storedItemId = $storedAnswer.children("items").children("item").attr("id");
  392. var previousItemId = $previousAnswer.children("items").children("item").attr("id");
  393. $items.each(function() {
  394. var $item = $(this);
  395. var itemId = $item.attr("id");
  396. var answerItemId = questionElementId + "_" + itemId;
  397. var $radioElement = $.createHtmlElement("input")
  398. .attr("id", answerItemId)
  399. .attr("name", questionElementId)
  400. .attr("type", "radio")
  401. .change(function() {
  402. answersChanged = true;
  403. countMetrics();
  404. })
  405. .change({ "question" : $question, "questionId" : questionId }, showDependencies);
  406. if ((itemId === storedItemId) || (itemId === previousItemId) && (storedItemId == null)) {
  407. $radioElement.attr("checked", "checked");
  408. } else {
  409. $radioElement.removeAttr("checked");
  410. }
  411. if (readOnly && (taskId != null)) {
  412. $radioElement.attr("disabled", true);
  413. }
  414. if ((vizitType === "VT_AUDIT") || (vizitType === "VT_GEMBA")) {
  415. if ((previousItemId == null) || (previousItemId === "")
  416. || ($items.filter("[id = '" + previousItemId + "']").attr("positive") === "false")) {
  417. if ($item.attr("positive") === "true") {
  418. $radioElement.attr("disabled", true);
  419. }
  420. }
  421. }
  422. var $radioElementLabel = $.createHtmlElement("label")
  423. .attr("for", answerItemId)
  424. .text($item.attr("name"));
  425. if (itemId === previousItemId) {
  426. $radioElementLabel.css("font-weight", "bold");
  427. }
  428. $questionAnswerField.append($.createHtmlElement("p").append($radioElement).append($radioElementLabel));
  429. });
  430. }
  431. if ($question.attr("activityCreation") === "true") {
  432. var $activityButton = $.createActivityButton(questionId);
  433. if (readOnly) {
  434. $activityButton.attr("disabled", true);
  435. }
  436. $buttonField.append($activityButton);
  437. }
  438. questionPanelMap[questionId] = $questionElement;
  439. $rightPanel.append($questionElement);
  440. });
  441. $leftPanel.append($menuGroup);
  442. });
  443. });
  444. $rightPanel.append(
  445. $.createHtmlElement("a")
  446. .addClass("upPagePanel").css("display", "block")
  447. .attr("href", "#top").attr("title", "Наверх")
  448. .text("Наверх страницы")
  449. .click(function() {
  450. $("#rightPanel").animate({ scrollTop : 0 }, "slow"); return false;
  451. })
  452. );
  453. //$("#checklistForm\\:checklistBody").html($root.html());
  454. //console.log("TIME blockMetrics = ", time);
  455. //console.log("TIME DURATION = ", (new Date().getTime() - start));
  456. $(".menuBlock").click(function() {
  457. var instance = $(this);
  458. $(".menuBlock").not(instance).each(function() {
  459. collapseBlock($(this));
  460. });
  461. if (instance.hasClass("od-collapse")) {
  462. expandBlock(instance);
  463. countMetrics();
  464. // Сдвигаем вопросы на текущую высоту таблицы показателей
  465. $("#rightPanel").css({ "top" : $("#metricTable").height() + 10 });
  466. // Открываем первую группу в блоке
  467. $(".menu-sub[id ^= '" + instance.attr("id") + "-gr-']").first().click();
  468. }
  469. });
  470. //$(".QuestionPanel").hide().removeClass("od-hidden");
  471. $(".menu-sub").click(function() {
  472. var instance = $(this);
  473. $(".menu-sub").not(instance).removeClass("od-selected");
  474. $(".QuestionPanel").hide();
  475. $(".ID" + instance.attr("id")).not(".dependent").show();
  476. instance.addClass("od-selected");
  477. if ((vizitType === "VT_SELF") || (vizitType === "VT_AUDIT") || (vizitType === "VT_GEMBA")) {
  478. showQuestions();
  479. }
  480. $("#rightPanel").animate({ scrollTop : 0 }, "fast");
  481. });
  482. $(".menuBlock").first().click();
  483. //console.log("TIME FULL = ", (new Date().getTime() - start));
  484. };
  485. /******************************************************************************
  486. * Description:
  487. * Return:
  488. *****************************************************************************/
  489. function collapseBlock(instance) {
  490. instance.removeClass("od-expand").addClass("od-collapse");
  491. $(".ID" + instance.attr("id")).removeClass("od-show").addClass("od-hidden");
  492. };
  493. /******************************************************************************
  494. * Description:
  495. * Return:
  496. *****************************************************************************/
  497. function expandBlock(instance) {
  498. instance.removeClass("od-collapse").addClass("od-expand");
  499. $(".ID" + instance.attr("id")).removeClass("od-hidden").addClass("od-show");
  500. };
  501. /******************************************************************************
  502. * Description:
  503. * Return:
  504. *****************************************************************************/
  505. function GetAnswers() {
  506. var $storedAnswers = $previousData.children("storedAnswers");
  507. var $blockMetrics = $previousData.children("blockMetrics");
  508. $storedAnswers.find("answer").remove();
  509. for (var questionId in questionMap) {
  510. var $question = questionMap[questionId];
  511. var $questionPanel = questionPanelMap[questionId];
  512. var $answer = $.createXmlElement("answer");
  513. $answer.attr("id", $question.attr("answerId"));
  514. $answer.attr("questionId", questionId);
  515. $answer.attr("taskId", taskId);
  516. var answerType = $question.children("answerType").attr("key");
  517. if (answerType === "AT_NUMERIC") {
  518. $answer.append($.createXmlElement("numberValue").text($questionPanel.find("input").val()));
  519. } else if (answerType === "AT_DATE") {
  520. $answer.append($.createXmlElement("dateValue").text($questionPanel.find("input").val()));
  521. } else if (answerType === "AT_STRING") {
  522. $answer.append($.createXmlElement("stringValue").text($questionPanel.find("input").val()));
  523. } else if (answerType === "AT_MEMO") {
  524. $answer.append($.createXmlElement("stringValue").text($questionPanel.find("textarea").val()));
  525. } else if (answerType === "AT_DDLIST-ONE") {
  526. var $items = $.createXmlElement("items");
  527. var itemId = $questionPanel.find(":selected").attr("id");
  528. if (itemId != null) {
  529. itemId = itemId.substring(itemId.lastIndexOf("_") + 1);
  530. $items.append($question.find("dic item[id = '" + itemId + "']").clone());
  531. }
  532. $answer.append($items.clone());
  533. } else if ((answerType === "AT_RADIO") || (answerType === "AT_CHECKLIST")) {
  534. var $items = $.createXmlElement("items");
  535. $questionPanel.find("input:checked").each(function() {
  536. var itemId = $(this).attr("id");
  537. itemId = itemId.substring(itemId.lastIndexOf("_") + 1);
  538. $items.append($question.find("dic item[id = '" + itemId + "']").clone());
  539. });
  540. $answer.append($items.clone());
  541. }
  542. $storedAnswers.append($answer.clone());
  543. }
  544. $blockMetrics.find("blockMetric").remove();
  545. for (var blockId in blockMap) {
  546. var $block = blockMap[blockId];
  547. $block.children("metrics").children("metric").each(function() {
  548. var $metric = $(this);
  549. var metricValue = $metric.attr("value");
  550. if (metricValue != null) {
  551. var $blockMetric = $.createBlockMetric(blockId, $metric.attr("id"), null, metricValue);
  552. $blockMetrics.append($blockMetric.clone());
  553. if ( ( (vizitType === "VT_AUDIT") || (vizitType === "VT_GEMBA") ) && ($metric.attr("key") === "M_RESULT") ) {
  554. var dispersion = (previousValue > 0) ? (1 - metricValue / previousValue) : 0;
  555. var reduction = $reduceIndexes.filter(function(index) {
  556. return ($(this).attr("dispStartValue") < dispersion) && ($(this).attr("dispEndValue") >= dispersion);
  557. }).attr("value");
  558. reduction = (reduction == null) ? 1 : reduction;
  559. var dispersedResult = metricValue * reduction;
  560. var $blockMetric = $.createBlockMetric(blockId, null, "M_DISPERSION", dispersion);
  561. $blockMetrics.append($blockMetric.clone());
  562. var $blockMetric = $.createBlockMetric(blockId, null, "M_REDUCE_INDEX", reduction);
  563. $blockMetrics.append($blockMetric.clone());
  564. var $blockMetric = $.createBlockMetric(blockId, null, "M_DISPERSED_RESULT", dispersedResult);
  565. $blockMetrics.append($blockMetric.clone());
  566. }
  567. }
  568. });
  569. }
  570. return $previousData.xml().toString();
  571. };
  572. /******************************************************************************
  573. * Description:
  574. * Return:
  575. *****************************************************************************/
  576. function ReadAnswers() {
  577. $("#checklistForm\\:currentAnswerXml").val(GetAnswers());
  578. };
  579. /******************************************************************************
  580. * Description:
  581. * Return:
  582. *****************************************************************************/
  583. function countMetrics() {
  584. var menuBlockId = $(".menuBlock.od-expand").attr("id");
  585. if (menuBlockId != null) {
  586. var blockId = menuBlockId.substring(menuBlockId.indexOf("-bl-") + 4);
  587. var $block = blockMap[blockId];
  588. $block.children("metrics").children("metric").each(function() {
  589. var $metric = $(this);
  590. var metricId = $metric.attr("id");
  591. var metricKey = $metric.attr("key");
  592. $metric.attr("value", 0.0);
  593. $block.find("group").each(function() {
  594. var $group = $(this);
  595. var groupPoints = 0.0;
  596. $group.find("question").each(function() {
  597. var $question = $(this);
  598. var questionId = $question.attr("id");
  599. var answerType = $question.children("answerType").attr("key");
  600. var $items = null;
  601. if ((answerType === "AT_RADIO") || (answerType === "AT_CHECKLIST")) {
  602. $items = questionPanelMap[questionId].find("input:checked");
  603. } else if (answerType === "AT_DDLIST-ONE") {
  604. $items = questionPanelMap[questionId].find(":selected");
  605. }
  606. if ($items != null) {
  607. $items.each(function() {
  608. var itemId = $(this).attr("id");
  609. itemId = itemId.substring(itemId.lastIndexOf("_") + 1);
  610. var points = $question.find("metricItem").filter(function(index) {
  611. var $id = $(this).children("id");
  612. return ($id.attr("metricId") === metricId) && ($id.attr("itemId") === itemId);
  613. }).attr("answerPoints");
  614. points = (points == null) ? 0.0 : points;
  615. if ((metricKey === "M_RESULT") || (metricKey === "M_QUALITY_CHECKUP")
  616. || (metricKey === "M_STANDARDS") || (metricKey === "M_MVS_STANDARDS")
  617. || (metricKey === "M_SALES_TECH") || (metricKey === "M_MVS_SALES_TECH")
  618. || (metricKey === "M_KNOWLEDGE") || (metricKey === "M_MVS_KNOWLEDGE")) {
  619. $metric.attr("value", parseFloat($metric.attr("value")) + parseFloat(points));
  620. } else if ((metricKey === "M_QUALITY") || (metricKey === "M_MVS_QUALITY")) {
  621. groupPoints = parseFloat(groupPoints) + parseFloat(points);
  622. }
  623. });
  624. }
  625. if (answerType === "AT_NUMERIC") {
  626. var value = questionPanelMap[questionId].find("input").val();
  627. var points = $question.find("answerRange").filter(function(index) {
  628. var $range = $(this).children("range");
  629. return ($range.attr("startValue") <= value) && ($range.attr("endValue") >= value);
  630. }).attr("answerPoints");
  631. points = (points == null) ? 0.0 : points;
  632. if (metricKey === "M_RESULT") {
  633. $metric.attr("value", parseFloat($metric.attr("value")) + parseFloat(points));
  634. }
  635. }
  636. });
  637. if ((metricKey === "M_QUALITY") || (metricKey === "M_MVS_QUALITY")) {
  638. var rate = $group.find("groupMetric metric[id = '" + metricId + "']").parent().attr("rate");
  639. if (rate == null) {
  640. rate = 0.0;
  641. }
  642. var groupMaxPoints = $group.attr("m-" + metricId + "-max");
  643. if ((groupMaxPoints != null) && (parseFloat(groupMaxPoints) > 0)) {
  644. $metric.attr("value", parseFloat($metric.attr("value")) + parseFloat(groupPoints) * parseFloat(rate) / parseFloat(groupMaxPoints));
  645. }
  646. }
  647. });
  648. });
  649. createTable($block);
  650. }
  651. };
  652. /******************************************************************************
  653. * Description:
  654. * Return:
  655. *****************************************************************************/
  656. function createTable($block) {
  657. var $metricTable = $("#metricTable");
  658. $metricTable.find("tr").remove();
  659. $block.children("metrics").children("metric").each(function() {
  660. var $metric = $(this);
  661. var metricKey = $metric.attr("key");
  662. var metricMax = $metric.attr("max");
  663. var metricValue = $metric.attr("value");
  664. if ((vizitType === "VT_SELF") || (vizitType === "VT_AUDIT") || (vizitType === "VT_GEMBA")) {
  665. if (metricKey === "M_RESULT") {
  666. var targetValue = Math.round(metricMax * targetPercent);
  667. var color = (metricValue < targetValue) ? "red" : "white";
  668. $metricTable.append(
  669. $.createHtmlElement("tr").append(
  670. $.createHtmlElement("td").attr("width", "220").text("Максимальная сумма баллов:")
  671. ).append(
  672. $.createHtmlElement("td").attr("width", "180").text(addPointText(metricMax))
  673. ).append(
  674. $.createHtmlElement("td").attr("width", "220").text("Цель:")
  675. ).append(
  676. $.createHtmlElement("td").attr("width", "180").text(addPointText(targetValue) + " (" + Math.round(targetPercent * 100) + "%)")
  677. )
  678. ).append(
  679. $.createHtmlElement("tr").append(
  680. $.createHtmlElement("td").text("Результат предыдущей проверки:")
  681. ).append(
  682. $.createHtmlElement("td").text(addPointText(previousValue) +
  683. ((targetValue !== 0) ? (" (" + Math.round(previousValue * 100 / targetValue) + "% от цели)") : ""))
  684. ).append(
  685. $.createHtmlElement("td").text("Результат текущей проверки:")
  686. ).append(
  687. $.createHtmlElement("td").text(addPointText(metricValue) +
  688. ((targetValue !== 0) ? (" (" + Math.round(metricValue * 100 / targetValue) + "% от цели)") : ""))
  689. .css("color", color)
  690. )
  691. );
  692. if (vizitType !== "VT_SELF") {
  693. var dispersionDiff = (previousValue > 0) ? (previousValue - metricValue) : 0;
  694. var dispersion = (previousValue > 0) ? (dispersionDiff / previousValue) : 0;
  695. var reduction = $reduceIndexes.filter(function(index) {
  696. return ($(this).attr("dispStartValue") < dispersion) && ($(this).attr("dispEndValue") >= dispersion);
  697. }).attr("value");
  698. reduction = (reduction == null) ? 1 : reduction;
  699. $metricTable.append(
  700. $.createHtmlElement("tr").append(
  701. $.createHtmlElement("td").text("Текущая дисперсия:")
  702. ).append(
  703. $.createHtmlElement("td").text(addPointText(dispersionDiff) + " (" + addPercent(dispersion) + ")")
  704. ).append(
  705. $.createHtmlElement("td").text("Понижающий коэффициент:")
  706. ).append(
  707. $.createHtmlElement("td").text(reduction)
  708. )
  709. ).append(
  710. $.createHtmlElement("tr").append(
  711. $.createHtmlElement("td").text("Результат с учетом дисперсии:")
  712. ).append(
  713. $.createHtmlElement("td").text(addPointText(Math.round(100 * metricValue * reduction) / 100))
  714. ).append(
  715. $.createHtmlElement("td").text("Рейтинг:")
  716. ).append(
  717. $.createHtmlElement("td").text(addPercent(metricValue * reduction / metricMax))
  718. )
  719. );
  720. } else {
  721. $metricTable.append(
  722. $.createHtmlElement("tr").append(
  723. $.createHtmlElement("td").attr("colspan", "2").css("text-align", "right").text("Рейтинг:")
  724. ).append(
  725. $.createHtmlElement("td").attr("colspan", "2").text(addPercent(metricValue / metricMax))
  726. )
  727. );
  728. }
  729. }
  730. } else {
  731. if (metricKey === "M_RESULT") {
  732. $metricTable.append(
  733. $.createHtmlElement("tr").append(
  734. $.createHtmlElement("td").attr("width", "400").text($metric.attr("name"))
  735. ).append(
  736. $.createHtmlElement("td").attr("width", "400").text(addPointText(metricValue) + " (" + addPercent(metricValue / metricMax) + ")")
  737. )
  738. );
  739. } else if ((metricKey === "M_STANDARDS") || (metricKey === "M_MVS_STANDARDS")
  740. || (metricKey === "M_SALES_TECH") || (metricKey === "M_MVS_SALES_TECH")
  741. || (metricKey === "M_KNOWLEDGE") || (metricKey === "M_MVS_KNOWLEDGE")
  742. || (metricKey === "M_QUALITY") || (metricKey === "M_MVS_QUALITY")
  743. || (metricKey === "M_QUALITY_CHECKUP")) {
  744. if ((metricMax != null) && (metricMax > 0)) {
  745. $metric.attr("value", metricValue / metricMax);
  746. }
  747. $metricTable.append(
  748. $.createHtmlElement("tr").append(
  749. $.createHtmlElement("td").attr("width", "400").text($metric.attr("name"))
  750. ).append(
  751. $.createHtmlElement("td").attr("width", "400").text(addPercent($metric.attr("value")))
  752. )
  753. );
  754. }
  755. }
  756. });
  757. };
  758. /******************************************************************************
  759. * Description:
  760. * Return:
  761. *****************************************************************************/
  762. function showQuestions() {
  763. var option = $("#showOptionsGroup input:checked").attr("id");
  764. var $allFormats = $("#inspectionFormatsGroup input");
  765. var $formats = $allFormats.find(":checked");
  766. $(".QuestionPanel.ID" + $(".menu-sub.od-selected").attr("id")).each(function() {
  767. var $questionBlock = $(this);
  768. var questionBlockId = $questionBlock.attr("id");
  769. var questionId = questionBlockId.substring(questionBlockId.indexOf("-q-") + 3);
  770. var visible = true;
  771. if ($allFormats.length > 0) {
  772. if ($formats.length > 0) {
  773. var $questionFormats = questionMap[questionId].find("inspectionFormat");
  774. $questionFormats = $questionFormats.filter(function(index) {
  775. return ($formats.filter("[id = '" + $(this).attr("key") + "']").attr("id") != null);
  776. });
  777. visible &= ($questionFormats.size() > 0);
  778. }
  779. }
  780. if (option != null) {
  781. var $answers = ($previousAnswers.size() > 0) ? $previousAnswers : $storedAnswers;
  782. var $item = $answers.filter("[questionId = '" + questionId + "']").find("item");
  783. if (option === "DI_SHOW_OPTION_YES") {
  784. visible &= ($item.attr("key") === "DI_YES_CERTIFICATION");
  785. } else if (option === "DI_SHOW_OPTION_NO") {
  786. visible &= ($item.attr("key") === "DI_NO_CERTIFICATION");
  787. }
  788. }
  789. if (visible) {
  790. $questionBlock.show();
  791. } else {
  792. $questionBlock.hide();
  793. }
  794. });
  795. };
  796. /******************************************************************************
  797. * Description:
  798. * Return:
  799. *****************************************************************************/
  800. function showDependencies(event) {
  801. var $question = event.data.question;
  802. var questionId = event.data.questionId;
  803. if (typeof dependentMap[questionId] !== "undefined") {
  804. var list = dependentMap[questionId];
  805. var answerType = $question.children("answerType").attr("key");
  806. var $items = null;
  807. if ((answerType === "AT_RADIO") || (answerType === "AT_CHECKLIST")) {
  808. $items = questionPanelMap[questionId].find(" input:checked");
  809. } else if (answerType === "AT_DDLIST-ONE") {
  810. $items = questionPanelMap[questionId].find(" :selected");
  811. }
  812. $question.children("dic").children("items").children("item").each(function() {
  813. var $item = $(this);
  814. var itemId = $item.attr("id");
  815. for (var i = 0, l = list.length; i < l; i++) {
  816. var dependentId = list[i].id;
  817. var dependentItemId = list[i].itemId;
  818. if (dependentItemId === itemId) {
  819. if ($items.filter("[id $= '_" + itemId + "']").size() !== 0) {
  820. questionPanelMap[dependentId].removeClass("dependent");
  821. if (questionGroupMap[dependentId] === questionGroupMap[questionId]) {
  822. questionPanelMap[dependentId].show();
  823. }
  824. showDependentQuestions(questionMap[dependentId], dependentId, questionGroupMap[questionId]);
  825. } else {
  826. questionPanelMap[dependentId].addClass("dependent");
  827. if (questionGroupMap[dependentId] === questionGroupMap[questionId]) {
  828. questionPanelMap[dependentId].hide();
  829. }
  830. hideDependentQuestions(dependentId, questionGroupMap[questionId]);
  831. }
  832. }
  833. }
  834. });
  835. }
  836. };
  837. /******************************************************************************
  838. * Description:
  839. * Return:
  840. *****************************************************************************/
  841. function showDependentQuestions($question, questionId, currentGroupId) {
  842. if (typeof dependentMap[questionId] !== "undefined") {
  843. var list = dependentMap[questionId];
  844. var answerType = $question.children("answerType").attr("key");
  845. var $items = null;
  846. if ((answerType === "AT_RADIO") || (answerType === "AT_CHECKLIST")) {
  847. $items = questionPanelMap[questionId].find(" input:checked");
  848. } else if (answerType === "AT_DDLIST-ONE") {
  849. $items = questionPanelMap[questionId].find(" :selected");
  850. }
  851. $question.children("dic").children("items").children("item").each(function() {
  852. var $item = $(this);
  853. var itemId = $item.attr("id");
  854. for (var i = 0, l = list.length; i < l; i++) {
  855. var dependentId = list[i].id;
  856. var dependentItemId = list[i].itemId;
  857. if (dependentItemId === itemId) {
  858. if ($items.filter("[id $= '_" + itemId + "']").size() !== 0) {
  859. questionPanelMap[dependentId].removeClass("dependent");
  860. if ((questionGroupMap[questionId] === currentGroupId)
  861. && (questionGroupMap[dependentId] === currentGroupId)) {
  862. questionPanelMap[dependentId].show();
  863. }
  864. showDependentQuestions(questionMap[dependentId], dependentId, questionGroupMap[questionId]);
  865. }
  866. }
  867. }
  868. });
  869. }
  870. };
  871. /******************************************************************************
  872. * Description:
  873. * Return:
  874. *****************************************************************************/
  875. function hideDependentQuestions(questionId, currentGroupId) {
  876. if (typeof dependentMap[questionId] !== "undefined") {
  877. var list = dependentMap[questionId];
  878. for (var i = 0, l = list.length; i < l; i++) {
  879. var dependentId = list[i].id;
  880. questionPanelMap[dependentId].addClass("dependent");
  881. if ((questionGroupMap[questionId] === currentGroupId)
  882. && (questionGroupMap[dependentId] === currentGroupId)) {
  883. questionPanelMap[dependentId].show();
  884. }
  885. hideDependentQuestions(dependentId, currentGroupId);
  886. }
  887. }
  888. };
  889. /******************************************************************************
  890. * Description: function checks questions with mandatory answers
  891. * Return: true - when all mandatory fields are filled,
  892. * false - otherwise (not all mandatory fields are filled)
  893. *****************************************************************************/
  894. function ValidateCL() {
  895. var fulfilled = true;
  896. for (var questionId in questionMap) {
  897. var $question = questionMap[questionId];
  898. if ((vizitType !== "VT_GEMBA") && ($question.attr("mandatory") === "true")
  899. || (vizitType === "VT_GEMBA") && ($question.attr("mandatoryManagement") === "true")) {
  900. var $questionPanel = questionPanelMap[questionId];
  901. var answerType = $question.children("answerType").attr("key");
  902. if ((answerType === "AT_NUMERIC") || (answerType === "AT_DATE") || (answerType === "AT_STRING")) {
  903. if ($.trim($questionPanel.find("input").val()) == "") {
  904. fulfilled = false;
  905. $questionPanel.addClass("shouldBeAnswered");
  906. // return false; // break
  907. } else {
  908. $questionPanel.removeClass("shouldBeAnswered");
  909. }
  910. } else if (answerType === "AT_MEMO") {
  911. if ($.trim($questionPanel.find("textarea").val()) == "") {
  912. fulfilled = false;
  913. $questionPanel.addClass("shouldBeAnswered");
  914. // return false; // break
  915. } else {
  916. $questionPanel.removeClass("shouldBeAnswered");
  917. }
  918. } else if (answerType === "AT_DDLIST-ONE") {
  919. if ($questionPanel.find(":selected").val() == null) {
  920. fulfilled = false;
  921. $questionPanel.addClass("shouldBeAnswered");
  922. // return false; // break
  923. } else {
  924. $questionPanel.removeClass("shouldBeAnswered");
  925. }
  926. } else if ((answerType === "AT_RADIO") || (answerType === "AT_CHECKLIST")) {
  927. if ($questionPanel.find("input:checked").val() == null) {
  928. fulfilled = false;
  929. $questionPanel.addClass("shouldBeAnswered");
  930. // return false; // break
  931. } else {
  932. $questionPanel.removeClass("shouldBeAnswered");
  933. }
  934. }
  935. }
  936. }
  937. return fulfilled;
  938. };
  939. /******************************************************************************
  940. * Description: function checks whether the answer to any question was changed
  941. * Return: true - some answer was changed,
  942. * false - otherwise (no one answer was changed)
  943. *****************************************************************************/
  944. function isAnswersChanged() {
  945. return answersChanged;
  946. };
  947. /******************************************************************************
  948. * Description:
  949. * Return:
  950. *****************************************************************************/
  951. $.createBlockMetric = function(blockId, metricId, metricKey, value) {
  952. var $blockMetric = $.createXmlElement("blockMetric")
  953. .attr("value", value);
  954. var $blockMetricId = $.createXmlElement("id")
  955. .attr("taskId", taskId).attr("blockId", blockId).attr("metricId", metricId);
  956. $blockMetric.append($blockMetricId.clone());
  957. if (metricKey != null) {
  958. var $blockMetricItem = $.createXmlElement("metric")
  959. .attr("key", metricKey);
  960. $blockMetric.append($blockMetricItem.clone());
  961. }
  962. return $blockMetric;
  963. };
  964. /******************************************************************************
  965. * Description:
  966. * Return:
  967. *****************************************************************************/
  968. $.createActivityButton = function(questionId) {
  969. return $.createHtmlElement("button")
  970. .addClass("buttonActivity")
  971. .attr("type", "button")
  972. .click(function() {
  973. var $question = questionMap[questionId];
  974. var $questionPanel = questionPanelMap[questionId];
  975. var answerType = $question.children("answerType").attr("key");
  976. var itemId = null;
  977. if (answerType === "AT_DDLIST-ONE") {
  978. itemId = $questionPanel.find(":selected").attr("id");
  979. if (itemId != null) {
  980. itemId = itemId.substring(itemId.lastIndexOf("_") + 1);
  981. }
  982. } else if (answerType === "AT_RADIO") {
  983. itemId = $questionPanel.find("input:checked").attr("id");
  984. if (itemId != null) {
  985. itemId = itemId.substring(itemId.lastIndexOf("_") + 1);
  986. }
  987. }
  988. addActivity(questionId, U(itemId));
  989. }).append($.createHtmlElement("span").text("Создать мероприятие"));
  990. };
  991. /******************************************************************************
  992. * Description:
  993. * Return:
  994. *****************************************************************************/
  995. $.createActivityLink = function(activityId, activityText) {
  996. return $.createHtmlElement("a")
  997. .text(activityText)
  998. .click(function() {
  999. openActivity(activityId);
  1000. });
  1001. };
  1002. /******************************************************************************
  1003. * Simple helper function creates a new html element from a name,
  1004. * so you don't have to add the brackets etc.
  1005. *****************************************************************************/
  1006. $.createHtmlElement = function(name) {
  1007. return $("<" + name + " />");
  1008. };
  1009. //TODO
  1010. $.createHtmlFragment = function(name) {
  1011. var fr = document.createDocumentFragment();
  1012. fr.appendChild(document.createElement(name));
  1013. return {fr: fr, ch: $(fr).children()};
  1014. };
  1015. /******************************************************************************
  1016. * Simple helper function creates a new xml element from a name,
  1017. * so you don't have to add the brackets etc.
  1018. *****************************************************************************/
  1019. $.createXmlElement = function(name) {
  1020. return $($.parseXML("<?xml version='1.0' encoding='UTF-8'?><" + name + " />")).find(name);
  1021. };
  1022. /******************************************************************************
  1023. * Description:
  1024. * Return:
  1025. *****************************************************************************/
  1026. Array.prototype.indexOf = function (obj, start) {
  1027. for (var i = (start || 0); i < this.length; i++) {
  1028. if (this[i] === obj) {
  1029. return i;
  1030. }
  1031. }
  1032. return -1;
  1033. };
  1034. /******************************************************************************
  1035. * Description:
  1036. * Return:
  1037. *****************************************************************************/
  1038. $.fn.xml = function() {
  1039. var r = [];
  1040. this.each(function() {
  1041. r.push($.xml(this));
  1042. });
  1043. return r;
  1044. };
  1045. $.xml = function(el) {
  1046. if (window.XMLSerializer) {
  1047. return (new XMLSerializer()).serializeToString(el);
  1048. }
  1049. var qw = function(s) {
  1050. return '"' + s.replace(/"/g, '&quot;') + '"';
  1051. };
  1052. if (!el) {
  1053. return "(null)";
  1054. }
  1055. var res = "";
  1056. var tag = el.nodeName;
  1057. var tagShow = tag.charAt(0) !== "#";
  1058. if (tagShow) {
  1059. res += '<' + tag;
  1060. }
  1061. if (el.attributes) {
  1062. res += $.map(
  1063. el.attributes,
  1064. function(attr) {
  1065. if (attr.specified && attr.name.charAt(0) !== '$')
  1066. return ' ' + attr.name + '=' + qw(attr.value);
  1067. }).join('');
  1068. }
  1069. if (tagShow && el.nodeValue == null && !el.hasChildNodes()) {
  1070. return res + " />";
  1071. }
  1072. if (tagShow) {
  1073. res += ">";
  1074. }
  1075. if (el.nodeType == 8) {
  1076. res += "<!-- " + el.nodeValue + " -->";
  1077. } else if (el.nodeValue != null) {
  1078. res += encodeXml(el.nodeValue);
  1079. }
  1080. if (el.hasChildNodes && el.hasChildNodes()) {
  1081. res += $.map(el.childNodes, function(child) {
  1082. return $.xml(child);
  1083. }).join('');
  1084. }
  1085. if (tagShow) {
  1086. res += '</' + tag + '>';
  1087. }
  1088. return res;
  1089. };
  1090. function encodeXml(s) {
  1091. return (s.
  1092. replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&apos;').replace(/</g, '&lt;').
  1093. replace(/>/g, '&gt;').replace(/\t/g, '&#x9;').replace(/\n/g, '&#xA;').replace(/\r/g, '&#xD;')
  1094. );
  1095. };
  1096. /******************************************************************************
  1097. * Description:
  1098. * Return:
  1099. *****************************************************************************/
  1100. function U(val) {
  1101. if (typeof (val) === "undefined") {
  1102. return "";
  1103. }
  1104. return val;
  1105. };
  1106. /******************************************************************************
  1107. * Description:
  1108. * Return:
  1109. *****************************************************************************/
  1110. function addPointText(points) {
  1111. var unit = points % 10;
  1112. var tens = Math.round(points / 10);
  1113. var text = points + " балл";
  1114. if ((tens !== 1) && (unit === 1)) {
  1115. } else if ((tens !== 1) && (unit >= 2) && (unit <= 4)) {
  1116. text += "а";
  1117. } else {
  1118. text += "ов";
  1119. }
  1120. return text;
  1121. };
  1122. function addPercent(value) {
  1123. return Math.round(10000 * value) / 100 + " %";
  1124. };