archives.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. define(['jquery', 'bootstrap', 'frontend', 'template', 'form'], function ($, undefined, Frontend, Template, Form) {
  2. var Controller = {
  3. my: function () {
  4. $(document).on('click', '.btn-delete', function () {
  5. var that = this;
  6. Layer.confirm("确认删除?删除后将不能恢复", {icon: 3}, function () {
  7. var url = $(that).data("url");
  8. Fast.api.ajax({
  9. url: url,
  10. }, function (data) {
  11. Layer.closeAll();
  12. location.reload();
  13. return false;
  14. });
  15. });
  16. return false;
  17. });
  18. },
  19. post: function () {
  20. require(['jquery-autocomplete'], function () {
  21. var search = $("#c-title");
  22. var form = search.closest("form");
  23. search.autoComplete({
  24. minChars: 1,
  25. cache: false,
  26. menuClass: 'autocomplete-searchtitle',
  27. header: Template('headertpl', {}),
  28. footer: '',
  29. source: function (term, response) {
  30. try {
  31. xhr.abort();
  32. } catch (e) {
  33. }
  34. xhr = $.getJSON(search.data("suggestion-url"), {q: term}, function (data) {
  35. response($.isArray(data) ? data : []);
  36. });
  37. },
  38. renderItem: function (item, search) {
  39. search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  40. var regexp = new RegExp("(" + search.replace(/[\,|\u3000|\uff0c]/, ' ').split(' ').join('|') + ")", "gi");
  41. Template.helper("replace", function (value) {
  42. return value.replace(regexp, "<b>$1</b>");
  43. });
  44. return Template('itemtpl', {item: item, search: search});
  45. },
  46. onSelect: function (e, term, item) {
  47. e.preventDefault();
  48. if (typeof callback === 'function') {
  49. callback.call(elem, term, item);
  50. } else {
  51. if ($(item).data("url")) {
  52. location.href = $(item).data("url");
  53. }
  54. return false;
  55. }
  56. }
  57. });
  58. });
  59. require(['jquery-tagsinput'], function () {
  60. //标签输入
  61. var elem = "#c-tags";
  62. var tags = $(elem);
  63. tags.tagsInput({
  64. width: 'auto',
  65. defaultText: '输入后回车确认',
  66. minInputWidth: 110,
  67. height: '36px',
  68. placeholderColor: '#999',
  69. onChange: function (row) {
  70. if (typeof callback === 'function') {
  71. } else {
  72. $(elem + "_addTag").focus();
  73. $(elem + "_tag").trigger("blur.autocomplete").focus();
  74. }
  75. },
  76. autocomplete: {
  77. url: 'cms.archives/tags_autocomplete',
  78. minChars: 1,
  79. menuClass: 'autocomplete-tags'
  80. }
  81. });
  82. });
  83. $(document).on('change', '#c-channel_id', function () {
  84. var model = $("option:selected", this).attr("model");
  85. var value = $(this).val();
  86. Fast.api.ajax({
  87. url: 'cms.archives/get_channel_fields',
  88. data: {channel_id: $(this).val(), archives_id: Config.archives_id}
  89. }, function (data) {
  90. if ($("#extend").data("model") != model) {
  91. $("div.form-group[data-field]").hide();
  92. $.each(data.contributefields, function (i, j) {
  93. $("div.form-group[data-field='" + j + "']").show();
  94. });
  95. $("#extend").html(data.html).data("model", model);
  96. Form.api.bindevent($("#extend"));
  97. }
  98. return false;
  99. });
  100. localStorage.setItem('last_channel_id', $(this).val());
  101. $("#c-channel_ids option").prop("disabled", true);
  102. $("#c-channel_ids option[model!='" + model + "']").prop("selected", false);
  103. $("#c-channel_id option[model='" + model + "']:not([disabled])").each(function () {
  104. $("#c-channel_ids option[model='" + $(this).attr("model") + "'][value='" + $(this).attr("value") + "']").prop("disabled", false);
  105. });
  106. if ($("#c-channel_ids").data("selectpicker")) {
  107. $("#c-channel_ids").data("selectpicker").refresh();
  108. }
  109. });
  110. $(document).on("fa.event.appendfieldlist", ".downloadlist", function (a) {
  111. Form.events.plupload(this);
  112. $(".fachoose", this).off("click");
  113. Form.events.faselect(this);
  114. });
  115. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  116. setTimeout(function () {
  117. location.href = Fast.api.fixurl('cms.archives/my');
  118. }, 1500);
  119. });
  120. // $("#c-channel_id").trigger("change");
  121. }
  122. };
  123. return Controller;
  124. });