123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- $.ajaxSetup({
- headers : {
- 'X-CSRF-TOKEN' : $("meta[name='x-csrf-token']").attr('content')
- }
- });
- //提示
- function art_dialog(data) {
- if(data.code == 'success') {
- art.dialog({
- content: data.msg,
- lock: true,
- ok: function() {
- if( data.path ){
- window.location.href = data.path;
- return false;
- }
- if( data.action=='add' || data.action=='edit' ){
- window.location.replace(document.referrer);
- return false;
- }
- location.reload();
- }
- });
- } else if(data.code == 'error') {
- // 替换掉令牌
- if( data.msg != '非法请求' && data.msg != '令牌错误' ){
- if( data.token ) $('input[name="_token"]').val(data.token);
- }
- art.dialog({
- content: data.msg,
- lock: true,
- ok: function() {
-
- }
- });
- }
- }
- //关闭提示
- function close_artDialog() {
- var list = art.dialog.list;
- for(var i in list) {
- list[i].close();
- };
- }
- var send_on = true;
- $(function() {
- //表单提交
- $(document).on('submit','.login-form,.post-form,.add-form,.edit-form',function(e) {
- e.preventDefault(); // 阻止表单默认提交行为
- if(!send_on) return false;
- var data = new FormData($(this)[0]);
- var action = $(this).attr('action');
- var method = $(this).attr('method');
- send_on = false;
- $.ajax({
- type: method,
- url: action,
- data: data,
- dataType: 'json',
- contentType: false, // 不设置内容类型
- processData: false, // 不处理发送的数据
- success: function(data) {
- send_on = true;
- art_dialog(data);
- },
- error: function(data) {
- send_on = true;
- art.dialog({
- content: data.responseJSON.message,
- lock: true,
- ok: function() {
-
- }
- });
- }
- });
- return false;
- })
- // 删除按钮
- $('.delete,.set_status').click(function() {
- var target = $(this).attr("data-url");
- art.dialog({
- content: '确认要执行该操作吗?',
- lock: true,
- ok: function() {
- $.get(target, function(data) {
- art_dialog(data);
- });
- }
- })
- });
-
- // Image Manager
- $(document).delegate('a[data-toggle=\'image\']', 'click', function(e) {
- e.preventDefault();
- $('.popover').popover('hide', function() {
- $('.popover').remove();
- });
- var element = this;
- $(element).popover({
- html: true,
- placement: 'right',
- trigger: 'manual',
- content: function() {
- 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>';
- }
- });
- $(element).popover('show');
- $('#button-image').on('click', function() {
- $('#modal-image').remove();
- $.ajax({
- url: filemanager_url + '?target=' + $(element).parent().find('input').attr('id') + '&thumb=' + $(element).attr('id'),
- dataType: 'html',
- beforeSend: function() {
- $('#button-image i').replaceWith('<i class="fa fa-circle-o-notch fa-spin"></i>');
- $('#button-image').prop('disabled', true);
- },
- complete: function() {
- $('#button-image i').replaceWith('<i class="fa fa-pencil"></i>');
- $('#button-image').prop('disabled', false);
- },
- success: function(html) {
- $('body').append('<div id="modal-image" class="modal">' + html + '</div>');
- $('#modal-image').modal('show');
- }
- });
- $(element).popover('hide', function() {
- $('.popover').remove();
- });
- });
- $('#button-clear').on('click', function() {
- $(element).find('img').attr('src', '/uploads/images/default/null.jpg');
- $(element).parent().find('input:first').attr('value', '');
- $(element).popover('hide', function() {
- $('.popover').remove();
- });
- });
- });
- })
- /**
- * 提交前修改表单属性
- *
- * @param object attr
- *
- */
- function alter_from_attr(attr){
- // 指定方法
- if( attr.method ) document.thisform.method = attr.method;
- if( attr.action ) document.thisform.action = attr.action;
- // 下载
- document.thisform.submit();
- // 恢复
- document.thisform.action = '';
- }
- //是否禁用
- function is_disabled($disabled){
- $('.edit_btn').parent('label').siblings().find('input').prop('disabled',$disabled);
- $('.edit_btn').parent('label').siblings().find('select').prop('disabled',$disabled);
- $('.edit_btn').parent('label').siblings().find('textarea').prop('disabled',$disabled);
- $('.selectpicker').selectpicker('render');
- $('.selectpicker').selectpicker('refresh');
- }
- /**
- * 确认信息
- *
- */
- var is_checked = false;
- $(function(){
- //表单提交
- $(document).on('submit','.check-form',function() {
- /* 关闭禁用,保证数据能正常上报*/
- is_disabled(false);
- // 处理数据与路径方式
- var data = $(this).serialize();
- var action = $(this).attr('action');
- var method = $(this).attr('method');
- var url = $(this).attr('check_url');
- // 如果
- if( !is_checked ) {
- // 获取参数
- $.ajax({
- type: method,
- url: url,
- data: data,
- success: function (data) {
- $('#myModal .modal-body').html(data);
- $('#myModal').modal('show');
- $('#myModalLabel').html(modal_title??'温馨提示');
- },
- error: function(response){
- /* 开启禁用 */
- is_disabled(true);
- art.dialog({
- content: '<p>'+response.responseJSON.message+'</p>',
- lock: true,
- ok:function(){
-
- }
- });
- },
- });
- // 阻止事件冒泡
- return false;
- }
- // 设置为未确认,避免未刷新页面时当前页面继续编辑不触发确认信息
- is_checked = false;
- // 发送
- $.ajax({
- type: method,
- url: action,
- data: data,
- dataType: 'json',
- success: function(data) {
- art_dialog(data);
- },
- error: function(response) {
- art.dialog({
- content: response.responseJSON.message,
- lock: true,
- ok: function() {
-
- }
- });
- }
- });
- // 阻止事件冒泡
- return false;
- })
- // 取消确认
- $(document).on('click','.cancel',function(){
- art.dialog({
- content: "<p class='text-red'>是否确认取消提交,将返回上一页</p>",
- lock: true,
- ok:function(){
- history.back(-1);
- }
- });
- })
- // 取消确认
- $(document).on('click','.modal_cancel',function(){
- /* 开启禁用 */
- is_disabled(true);
- })
- // 重新提交
- $(document).on('click','.is_checked',function(){
- // 确认已检查
- is_checked = true;
- // 重新提交
- $('.check-form').submit();
- // 关闭模态框
- $('#myModal').modal('hide');
- })
- // 编辑按钮
- $(document).on('click','.edit_btn',function(){
- // 关闭禁用
- $(this).parent('label').siblings().find('input').prop('disabled',false);
- $(this).parent('label').siblings().find('select').prop('disabled',false);
- $(this).parent('label').siblings().find('textarea').prop('disabled',false);
- $('.selectpicker').selectpicker('render');
- $('.selectpicker').selectpicker('refresh');
- })
- // 显示预览
- $(document).on('click','.show_eye_modal',function(){
- // 获取值
- var values = $(this).parent('label').siblings().find('input').val();
- var columnId = $(this).attr('column_id');
- var type_id = $(this).attr('column_type_id');
- // 如果不存在
- if( !values ) values = $(this).parent('label').siblings().find('select').val();
- if( !values ) values = $(this).parent('label').siblings().find('textarea').val();
- // 发送
- $.ajax({
- type: 'GET',
- url: '/admin/need_baseline/show_view',
- data: {'column_id':columnId,'type_id':type_id,'values':values},
- success: function(data) {
- console.log(data);
- $('#myModal .modal-body').html(data);
- $('#myModal').modal('show');
- $('#myModalLabel').html('预览');
- },
- error: function(response) {
- art.dialog({
- content: response.status + response.responseJSON.message,
- lock: true,
- ok: function() {
-
- }
- });
- }
- });
- // 阻止事件冒泡
- return false;
- })
- //表单action提交
- $(document).on('submit','.action-form',function() {
- /* 关闭禁用,保证数据能正常上报*/
- is_disabled(false);
- // 处理数据与路径方式
- var data = $(this).serialize();
- var action = $(this).attr('action');
- var method = $(this).attr('method');
- // 发送
- $.ajax({
- type: method,
- url: action,
- data: data,
- dataType: 'json',
- success: function(data) {
- art_dialog(data);
- },
- error: function(response) {
- art.dialog({
- content: response.responseJSON.message,
- lock: true,
- ok: function() {
- }
- });
- }
- });
- // 阻止事件冒泡
- return false;
- })
- $(function(){
- $('.modal_show').click(function(){
- // 获取链接
- var url = $(this).attr('data-url');
- // 发送
- $.ajax({
- type: 'GET',
- url: url,
- data: {},
- success: function(data) {
- $('#myModal .modal-body').html(data);
- $('#myModal').modal('show');
- $('.selectpicker').selectpicker('render');
- },
- error: function(response) {
- art.dialog({
- content: response.status + response.responseJSON.message,
- lock: true,
- ok: function() {
-
- }
- });
- }
- });
- })
-
- })
- })
|