PageRenderTime 192ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/SberbankAuditSUP/HTML/checklist.js

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