edu_admin.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. document.thisform.action = '';
  151. }
  152. //是否禁用
  153. function is_disabled($disabled){
  154. $('.edit_btn').parent('label').siblings().find('input').prop('disabled',$disabled);
  155. $('.edit_btn').parent('label').siblings().find('select').prop('disabled',$disabled);
  156. $('.edit_btn').parent('label').siblings().find('textarea').prop('disabled',$disabled);
  157. $('.selectpicker').selectpicker('render');
  158. $('.selectpicker').selectpicker('refresh');
  159. }
  160. /**
  161. * 确认信息
  162. *
  163. */
  164. var is_checked = false;
  165. $(function(){
  166. //表单提交
  167. $(document).on('submit','.check-form',function() {
  168. /* 关闭禁用,保证数据能正常上报*/
  169. is_disabled(false);
  170. // 处理数据与路径方式
  171. var data = $(this).serialize();
  172. var action = $(this).attr('action');
  173. var method = $(this).attr('method');
  174. var url = $(this).attr('check_url');
  175. // 如果
  176. if( !is_checked ) {
  177. // 获取参数
  178. $.ajax({
  179. type: method,
  180. url: url,
  181. data: data,
  182. success: function (data) {
  183. $('#myModal .modal-body').html(data);
  184. $('#myModal').modal('show');
  185. $('#myModalLabel').html(modal_title??'温馨提示');
  186. },
  187. error: function(response){
  188. /* 开启禁用 */
  189. is_disabled(true);
  190. art.dialog({
  191. content: '<p>'+response.responseJSON.message+'</p>',
  192. lock: true,
  193. ok:function(){
  194. }
  195. });
  196. },
  197. });
  198. // 阻止事件冒泡
  199. return false;
  200. }
  201. // 设置为未确认,避免未刷新页面时当前页面继续编辑不触发确认信息
  202. is_checked = false;
  203. // 发送
  204. $.ajax({
  205. type: method,
  206. url: action,
  207. data: data,
  208. dataType: 'json',
  209. success: function(data) {
  210. art_dialog(data);
  211. },
  212. error: function(response) {
  213. art.dialog({
  214. content: response.responseJSON.message,
  215. lock: true,
  216. ok: function() {
  217. }
  218. });
  219. }
  220. });
  221. // 阻止事件冒泡
  222. return false;
  223. })
  224. // 取消确认
  225. $(document).on('click','.cancel',function(){
  226. art.dialog({
  227. content: "<p class='text-red'>是否确认取消提交,将返回上一页</p>",
  228. lock: true,
  229. ok:function(){
  230. history.back(-1);
  231. }
  232. });
  233. })
  234. // 取消确认
  235. $(document).on('click','.modal_cancel',function(){
  236. /* 开启禁用 */
  237. is_disabled(true);
  238. })
  239. // 重新提交
  240. $(document).on('click','.is_checked',function(){
  241. // 确认已检查
  242. is_checked = true;
  243. // 重新提交
  244. $('.check-form').submit();
  245. // 关闭模态框
  246. $('#myModal').modal('hide');
  247. })
  248. // 编辑按钮
  249. $(document).on('click','.edit_btn',function(){
  250. // 关闭禁用
  251. $(this).parent('label').siblings().find('input').prop('disabled',false);
  252. $(this).parent('label').siblings().find('select').prop('disabled',false);
  253. $(this).parent('label').siblings().find('textarea').prop('disabled',false);
  254. $('.selectpicker').selectpicker('render');
  255. $('.selectpicker').selectpicker('refresh');
  256. })
  257. // 显示预览
  258. $(document).on('click','.show_eye_modal',function(){
  259. // 获取值
  260. var values = $(this).parent('label').siblings().find('input').val();
  261. var columnId = $(this).attr('column_id');
  262. var type_id = $(this).attr('column_type_id');
  263. // 如果不存在
  264. if( !values ) values = $(this).parent('label').siblings().find('select').val();
  265. if( !values ) values = $(this).parent('label').siblings().find('textarea').val();
  266. // 发送
  267. $.ajax({
  268. type: 'GET',
  269. url: '/admin/need_baseline/show_view',
  270. data: {'column_id':columnId,'type_id':type_id,'values':values},
  271. success: function(data) {
  272. console.log(data);
  273. $('#myModal .modal-body').html(data);
  274. $('#myModal').modal('show');
  275. $('#myModalLabel').html('预览');
  276. },
  277. error: function(response) {
  278. art.dialog({
  279. content: response.status + response.responseJSON.message,
  280. lock: true,
  281. ok: function() {
  282. }
  283. });
  284. }
  285. });
  286. // 阻止事件冒泡
  287. return false;
  288. })
  289. //表单action提交
  290. $(document).on('submit','.action-form',function() {
  291. /* 关闭禁用,保证数据能正常上报*/
  292. is_disabled(false);
  293. // 处理数据与路径方式
  294. var data = $(this).serialize();
  295. var action = $(this).attr('action');
  296. var method = $(this).attr('method');
  297. // 发送
  298. $.ajax({
  299. type: method,
  300. url: action,
  301. data: data,
  302. dataType: 'json',
  303. success: function(data) {
  304. art_dialog(data);
  305. },
  306. error: function(response) {
  307. art.dialog({
  308. content: response.responseJSON.message,
  309. lock: true,
  310. ok: function() {
  311. }
  312. });
  313. }
  314. });
  315. // 阻止事件冒泡
  316. return false;
  317. })
  318. $(function(){
  319. $('.modal_show').click(function(){
  320. // 获取链接
  321. var url = $(this).attr('data-url');
  322. // 发送
  323. $.ajax({
  324. type: 'GET',
  325. url: url,
  326. data: {},
  327. success: function(data) {
  328. $('#myModal .modal-body').html(data);
  329. $('#myModal').modal('show');
  330. $('.selectpicker').selectpicker('render');
  331. },
  332. error: function(response) {
  333. art.dialog({
  334. content: response.status + response.responseJSON.message,
  335. lock: true,
  336. ok: function() {
  337. }
  338. });
  339. }
  340. });
  341. })
  342. })
  343. })