edu_admin.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. $.ajaxSetup({
  2. headers : {
  3. 'X-CSRF-TOKEN' : $("meta[name='x-csrf-token']").attr('content')
  4. }
  5. });
  6. //提示
  7. function art_dialog(data) {
  8. if(data.code == 'success') {
  9. art.dialog({
  10. content: data.msg,
  11. lock: true,
  12. ok: function() {
  13. if( data.path ){
  14. window.location.href = data.path;
  15. return false;
  16. }
  17. if( data.action=='add' || data.action=='edit' ){
  18. window.location.replace(document.referrer);
  19. return false;
  20. }
  21. location.reload();
  22. }
  23. });
  24. } else if(data.code == 'error') {
  25. // 替换掉令牌
  26. if( data.msg != '非法请求' && data.msg != '令牌错误' ){
  27. if( data.token ) $('input[name="_token"]').val(data.token);
  28. }
  29. art.dialog({
  30. content: data.msg,
  31. lock: true,
  32. ok: function() {
  33. }
  34. });
  35. }
  36. }
  37. //关闭提示
  38. function close_artDialog() {
  39. var list = art.dialog.list;
  40. for(var i in list) {
  41. list[i].close();
  42. };
  43. }
  44. var send_on = true;
  45. $(function() {
  46. //表单提交
  47. $(document).on('submit','.login-form,.post-form,.add-form,.edit-form',function(e) {
  48. e.preventDefault(); // 阻止表单默认提交行为
  49. if(!send_on) return false;
  50. var data = new FormData($(this)[0]);
  51. var action = $(this).attr('action');
  52. var method = $(this).attr('method');
  53. send_on = false;
  54. $.ajax({
  55. type: method,
  56. url: action,
  57. data: data,
  58. dataType: 'json',
  59. contentType: false, // 不设置内容类型
  60. processData: false, // 不处理发送的数据
  61. success: function(data) {
  62. send_on = true;
  63. art_dialog(data);
  64. },
  65. error: function(data) {
  66. send_on = true;
  67. art.dialog({
  68. content: data.responseJSON.message,
  69. lock: true,
  70. ok: function() {
  71. }
  72. });
  73. }
  74. });
  75. return false;
  76. })
  77. // 删除按钮
  78. $('.delete,.set_status').click(function() {
  79. var target = $(this).attr("data-url");
  80. art.dialog({
  81. content: '确认要执行该操作吗?',
  82. lock: true,
  83. ok: function() {
  84. $.get(target, function(data) {
  85. art_dialog(data);
  86. });
  87. }
  88. })
  89. });
  90. // Image Manager
  91. $(document).delegate('a[data-toggle=\'image\']', 'click', function(e) {
  92. e.preventDefault();
  93. $('.popover').popover('hide', function() {
  94. $('.popover').remove();
  95. });
  96. var element = this;
  97. $(element).popover({
  98. html: true,
  99. placement: 'right',
  100. trigger: 'manual',
  101. content: function() {
  102. return '<button type="button" id="button-image" class="btn btn-primary"><i class="fa fa-pencil"></i></button> <button type="button" id="button-clear" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>';
  103. }
  104. });
  105. $(element).popover('show');
  106. $('#button-image').on('click', function() {
  107. $('#modal-image').remove();
  108. $.ajax({
  109. url: filemanager_url + '?target=' + $(element).parent().find('input').attr('id') + '&thumb=' + $(element).attr('id'),
  110. dataType: 'html',
  111. beforeSend: function() {
  112. $('#button-image i').replaceWith('<i class="fa fa-circle-o-notch fa-spin"></i>');
  113. $('#button-image').prop('disabled', true);
  114. },
  115. complete: function() {
  116. $('#button-image i').replaceWith('<i class="fa fa-pencil"></i>');
  117. $('#button-image').prop('disabled', false);
  118. },
  119. success: function(html) {
  120. $('body').append('<div id="modal-image" class="modal">' + html + '</div>');
  121. $('#modal-image').modal('show');
  122. }
  123. });
  124. $(element).popover('hide', function() {
  125. $('.popover').remove();
  126. });
  127. });
  128. $('#button-clear').on('click', function() {
  129. $(element).find('img').attr('src', '/uploads/images/default/null.jpg');
  130. $(element).parent().find('input:first').attr('value', '');
  131. $(element).popover('hide', function() {
  132. $('.popover').remove();
  133. });
  134. });
  135. });
  136. })
  137. /**
  138. * 提交前修改表单属性
  139. *
  140. * @param object attr
  141. *
  142. */
  143. function alter_from_attr(attr){
  144. // 指定方法
  145. if( attr.method ) document.thisform.method = attr.method;
  146. if( attr.action ) document.thisform.action = attr.action;
  147. // 下载
  148. document.thisform.submit();
  149. }
  150. //是否禁用
  151. function is_disabled($disabled){
  152. $('.edit_btn').parent('label').siblings().find('input').prop('disabled',$disabled);
  153. $('.edit_btn').parent('label').siblings().find('select').prop('disabled',$disabled);
  154. $('.edit_btn').parent('label').siblings().find('textarea').prop('disabled',$disabled);
  155. $('.selectpicker').selectpicker('render');
  156. $('.selectpicker').selectpicker('refresh');
  157. }
  158. /**
  159. * 确认信息
  160. *
  161. */
  162. var is_checked = false;
  163. $(function(){
  164. //表单提交
  165. $(document).on('submit','.check-form',function() {
  166. /* 关闭禁用,保证数据能正常上报*/
  167. is_disabled(false);
  168. // 处理数据与路径方式
  169. var data = $(this).serialize();
  170. var action = $(this).attr('action');
  171. var method = $(this).attr('method');
  172. var url = $(this).attr('check_url');
  173. // 如果
  174. if( !is_checked ) {
  175. // 获取参数
  176. $.ajax({
  177. type: method,
  178. url: url,
  179. data: data,
  180. success: function (data) {
  181. $('#myModal .modal-body').html(data);
  182. $('#myModal').modal('show');
  183. $('#myModalLabel').html(modal_title??'温馨提示');
  184. },
  185. error: function(response){
  186. /* 开启禁用 */
  187. is_disabled(true);
  188. art.dialog({
  189. content: '<p>'+response.responseJSON.message+'</p>',
  190. lock: true,
  191. ok:function(){
  192. }
  193. });
  194. },
  195. });
  196. // 阻止事件冒泡
  197. return false;
  198. }
  199. // 设置为未确认,避免未刷新页面时当前页面继续编辑不触发确认信息
  200. is_checked = false;
  201. // 发送
  202. $.ajax({
  203. type: method,
  204. url: action,
  205. data: data,
  206. dataType: 'json',
  207. success: function(data) {
  208. art_dialog(data);
  209. },
  210. error: function(response) {
  211. art.dialog({
  212. content: response.responseJSON.message,
  213. lock: true,
  214. ok: function() {
  215. }
  216. });
  217. }
  218. });
  219. // 阻止事件冒泡
  220. return false;
  221. })
  222. // 取消确认
  223. $(document).on('click','.cancel',function(){
  224. art.dialog({
  225. content: "<p class='text-red'>是否确认取消提交,将返回上一页</p>",
  226. lock: true,
  227. ok:function(){
  228. history.back(-1);
  229. }
  230. });
  231. })
  232. // 取消确认
  233. $(document).on('click','.modal_cancel',function(){
  234. /* 开启禁用 */
  235. is_disabled(true);
  236. })
  237. // 重新提交
  238. $(document).on('click','.is_checked',function(){
  239. // 确认已检查
  240. is_checked = true;
  241. // 重新提交
  242. $('.check-form').submit();
  243. // 关闭模态框
  244. $('#myModal').modal('hide');
  245. })
  246. // 编辑按钮
  247. $(document).on('click','.edit_btn',function(){
  248. // 关闭禁用
  249. $(this).parent('label').siblings().find('input').prop('disabled',false);
  250. $(this).parent('label').siblings().find('select').prop('disabled',false);
  251. $(this).parent('label').siblings().find('textarea').prop('disabled',false);
  252. $('.selectpicker').selectpicker('render');
  253. $('.selectpicker').selectpicker('refresh');
  254. })
  255. // 显示预览
  256. $(document).on('click','.show_eye_modal',function(){
  257. // 获取值
  258. var values = $(this).parent('label').siblings().find('input').val();
  259. var columnId = $(this).attr('column_id');
  260. var type_id = $(this).attr('column_type_id');
  261. // 如果不存在
  262. if( !values ) values = $(this).parent('label').siblings().find('select').val();
  263. if( !values ) values = $(this).parent('label').siblings().find('textarea').val();
  264. // 发送
  265. $.ajax({
  266. type: 'GET',
  267. url: '/admin/need_baseline/show_view',
  268. data: {'column_id':columnId,'type_id':type_id,'values':values},
  269. success: function(data) {
  270. console.log(data);
  271. $('#myModal .modal-body').html(data);
  272. $('#myModal').modal('show');
  273. $('#myModalLabel').html('预览');
  274. },
  275. error: function(response) {
  276. art.dialog({
  277. content: response.status + response.responseJSON.message,
  278. lock: true,
  279. ok: function() {
  280. }
  281. });
  282. }
  283. });
  284. // 阻止事件冒泡
  285. return false;
  286. })
  287. $(function(){
  288. $('.modal_show').click(function(){
  289. // 获取链接
  290. var url = $(this).attr('data-url');
  291. // 发送
  292. $.ajax({
  293. type: 'GET',
  294. url: url,
  295. data: {},
  296. success: function(data) {
  297. $('#myModal .modal-body').html(data);
  298. $('#myModal').modal('show');
  299. $('.selectpicker').selectpicker('render');
  300. },
  301. error: function(response) {
  302. art.dialog({
  303. content: response.status + response.responseJSON.message,
  304. lock: true,
  305. ok: function() {
  306. }
  307. });
  308. }
  309. });
  310. })
  311. })
  312. })