aspnet.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * DevExtreme (aspnet.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. ! function(factory) {
  11. if ("function" === typeof define && define.amd) {
  12. define(function(require, exports, module) {
  13. module.exports = factory(require("jquery"), require("./ui/set_template_engine"), require("./ui/widget/ui.template_base").renderedCallbacks, require("./core/guid"), require("./ui/validation_engine"), require("./core/utils/iterator"), require("./core/utils/dom").extractTemplateMarkup, require("./core/utils/string").encodeHtml)
  14. })
  15. } else {
  16. var ui = DevExpress.ui;
  17. DevExpress.aspnet = factory(window.jQuery, ui && ui.setTemplateEngine, ui && ui.templateRendered, DevExpress.data.Guid, DevExpress.validationEngine, DevExpress.utils.iterator, DevExpress.utils.dom.extractTemplateMarkup, DevExpress.utils.string.encodeHtml)
  18. }
  19. }(function($, _setTemplateEngine, templateRendered, Guid, validationEngine, iteratorUtils, extractTemplateMarkup, encodeHtml) {
  20. var templateCompiler = createTemplateCompiler();
  21. var pendingCreateComponentRoutines = [];
  22. var _enableAlternativeTemplateTags = true;
  23. function createTemplateCompiler() {
  24. var OPEN_TAG = "<%",
  25. CLOSE_TAG = "%>",
  26. ENCODE_QUALIFIER = "-",
  27. INTERPOLATE_QUALIFIER = "=";
  28. var EXTENDED_OPEN_TAG = /[<[]%/g,
  29. EXTENDED_CLOSE_TAG = /%[>\]]/g;
  30. function acceptText(bag, text) {
  31. if (text) {
  32. bag.push("_.push(", JSON.stringify(text), ");")
  33. }
  34. }
  35. function acceptCode(bag, code) {
  36. var encode = code.charAt(0) === ENCODE_QUALIFIER,
  37. value = code.substr(1),
  38. interpolate = code.charAt(0) === INTERPOLATE_QUALIFIER;
  39. if (encode || interpolate) {
  40. bag.push("_.push(");
  41. bag.push(encode ? "arguments[1](" + value + ")" : value);
  42. bag.push(");")
  43. } else {
  44. bag.push(code + "\n")
  45. }
  46. }
  47. return function(text) {
  48. var bag = ["var _ = [];", "with(obj||{}) {"],
  49. chunks = text.split(_enableAlternativeTemplateTags ? EXTENDED_OPEN_TAG : OPEN_TAG);
  50. acceptText(bag, chunks.shift());
  51. for (var i = 0; i < chunks.length; i++) {
  52. var tmp = chunks[i].split(_enableAlternativeTemplateTags ? EXTENDED_CLOSE_TAG : CLOSE_TAG);
  53. if (2 !== tmp.length) {
  54. throw "Template syntax error"
  55. }
  56. acceptCode(bag, tmp[0]);
  57. acceptText(bag, tmp[1])
  58. }
  59. bag.push("}", "return _.join('')");
  60. return new Function("obj", bag.join(""))
  61. }
  62. }
  63. function createTemplateEngine() {
  64. return {
  65. compile: function(element) {
  66. return templateCompiler(extractTemplateMarkup(element))
  67. },
  68. render: function(template, data) {
  69. var html = template(data, encodeHtml);
  70. var dxMvcExtensionsObj = window.MVCx;
  71. if (dxMvcExtensionsObj && !dxMvcExtensionsObj.isDXScriptInitializedOnLoad) {
  72. html = html.replace(/(<script[^>]+)id="dxss_.+?"/g, "$1")
  73. }
  74. return html
  75. }
  76. }
  77. }
  78. function getValidationSummary(validationGroup) {
  79. var result;
  80. $(".dx-validationsummary").each(function(_, element) {
  81. var summary = $(element).data("dxValidationSummary");
  82. if (summary && summary.option("validationGroup") === validationGroup) {
  83. result = summary;
  84. return false
  85. }
  86. });
  87. return result
  88. }
  89. function createValidationSummaryItemsFromValidators(validators, editorNames) {
  90. var items = [];
  91. iteratorUtils.each(validators, function(_, validator) {
  92. var widget = validator.$element().data("dx-validation-target");
  93. if (widget && $.inArray(widget.option("name"), editorNames) > -1) {
  94. items.push({
  95. text: widget.option("validationError.message"),
  96. validator: validator
  97. })
  98. }
  99. });
  100. return items
  101. }
  102. function createComponent(name, options, id, validatorOptions) {
  103. var selector = "#" + String(id).replace(/[^\w-]/g, "\\$&");
  104. pendingCreateComponentRoutines.push(function() {
  105. var $element = $(selector);
  106. if ($element.length) {
  107. var $component = $(selector)[name](options);
  108. if ($.isPlainObject(validatorOptions)) {
  109. $component.dxValidator(validatorOptions)
  110. }
  111. return true
  112. }
  113. return false
  114. })
  115. }
  116. templateRendered.add(function() {
  117. var snapshot = pendingCreateComponentRoutines.slice();
  118. var leftover = [];
  119. pendingCreateComponentRoutines = [];
  120. snapshot.forEach(function(func) {
  121. if (!func()) {
  122. leftover.push(func)
  123. }
  124. });
  125. pendingCreateComponentRoutines = pendingCreateComponentRoutines.concat(leftover)
  126. });
  127. return {
  128. createComponent: createComponent,
  129. renderComponent: function(name, options, id, validatorOptions) {
  130. id = id || "dx-" + new Guid;
  131. createComponent(name, options, id, validatorOptions);
  132. return '<div id="' + id + '"></div>'
  133. },
  134. getEditorValue: function(inputName) {
  135. var $widget = $("input[name='" + inputName + "']").closest(".dx-widget");
  136. if ($widget.length) {
  137. var dxComponents = $widget.data("dxComponents"),
  138. widget = $widget.data(dxComponents[0]);
  139. if (widget) {
  140. return widget.option("value")
  141. }
  142. }
  143. },
  144. setTemplateEngine: function() {
  145. if (_setTemplateEngine) {
  146. _setTemplateEngine(createTemplateEngine())
  147. }
  148. },
  149. enableAlternativeTemplateTags: function(value) {
  150. _enableAlternativeTemplateTags = value
  151. },
  152. createValidationSummaryItems: function(validationGroup, editorNames) {
  153. var groupConfig, items, summary = getValidationSummary(validationGroup);
  154. if (summary) {
  155. groupConfig = validationEngine.getGroupConfig(validationGroup);
  156. if (groupConfig) {
  157. items = createValidationSummaryItemsFromValidators(groupConfig.validators, editorNames);
  158. items.length && summary.option("items", items)
  159. }
  160. }
  161. }
  162. }
  163. });