新增自定义编辑删除按钮

pull/146/MERGE
Karson 2019-10-12 11:45:40 +08:00
parent 9b2ec96a03
commit b6f2307737
2 changed files with 195 additions and 172 deletions

View File

@ -6638,8 +6638,8 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
*/ */
;(function(factory) { ;(function(factory) {
typeof module === 'object' && module.exports ? module.exports = factory( require( 'jquery' ) ) : typeof module === 'object' && module.exports ? module.exports = factory( require( 'jquery' ) ) :
typeof define === 'function' && define.amd ? define('validator-core',['jquery'], factory) : typeof define === 'function' && define.amd ? define('validator-core',['jquery'], factory) :
factory(jQuery); factory(jQuery);
}(function($, undefined) { }(function($, undefined) {
'use strict'; 'use strict';
@ -6746,56 +6746,56 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
/** jQuery Plugin /** jQuery Plugin
* @param {Object} options * @param {Object} options
debug {Boolean} 0 Whether to enable debug mode debug {Boolean} 0 Whether to enable debug mode
timely {Number} 1 Whether to enable timely validation timely {Number} 1 Whether to enable timely validation
theme {String} 'default' Theme name theme {String} 'default' Theme name
stopOnError {Boolean} false Whether to stop validate when found an error input stopOnError {Boolean} false Whether to stop validate when found an error input
focusCleanup {Boolean} false Whether to clean up the field message when focus the field focusCleanup {Boolean} false Whether to clean up the field message when focus the field
focusInvalid {Boolean} true Whether to focus the field that is invalid focusInvalid {Boolean} true Whether to focus the field that is invalid
ignoreBlank {Boolean} false When the field has no value, whether to ignore validation ignoreBlank {Boolean} false When the field has no value, whether to ignore validation
ignore {jqSelector} '' Ignored fields (Using jQuery selector) ignore {jqSelector} '' Ignored fields (Using jQuery selector)
beforeSubmit {Function} Do something before submit form beforeSubmit {Function} Do something before submit form
dataFilter {Function} Convert ajax results dataFilter {Function} Convert ajax results
valid {Function} Triggered when the form is valid valid {Function} Triggered when the form is valid
invalid {Function} Triggered when the form is invalid invalid {Function} Triggered when the form is invalid
validClass {String} 'n-valid' Add this class name to a valid field validClass {String} 'n-valid' Add this class name to a valid field
invalidClass {String} 'n-invalid' Add this class name to a invalid field invalidClass {String} 'n-invalid' Add this class name to a invalid field
bindClassTo {jqSelector} ':verifiable' Which element should the className binding to bindClassTo {jqSelector} ':verifiable' Which element should the className binding to
display {Function} Callback function to get dynamic display display {Function} Callback function to get dynamic display
target {Function} Callback function to get dynamic target target {Function} Callback function to get dynamic target
msgShow {Function} Trigger this callback when show message msgShow {Function} Trigger this callback when show message
msgHide {Function} Trigger this callback when hide message msgHide {Function} Trigger this callback when hide message
msgWrapper {String} 'span' Message wrapper tag name msgWrapper {String} 'span' Message wrapper tag name
msgMaker {Function} Callback function to make message HTML msgMaker {Function} Callback function to make message HTML
msgArrow {String} Message arrow template msgArrow {String} Message arrow template
msgIcon {String} Message icon template msgIcon {String} Message icon template
msgStyle {String} Custom message css style msgStyle {String} Custom message css style
msgClass {String} Additional added to the message class names msgClass {String} Additional added to the message class names
formClass {String} Additional added to the form class names formClass {String} Additional added to the form class names
messages {Object} Custom messages for the current instance messages {Object} Custom messages for the current instance
rules {Object} Custom rules for the current instance rules {Object} Custom rules for the current instance
fields {Object} Field validation configuration fields {Object} Field validation configuration
{String} key name|#id {String} key name|#id
{String|Object} value Rule string or an object which can pass more arguments {String|Object} value Rule string or an object which can pass more arguments
fields[key][rule] {String} Rule string fields[key][rule] {String} Rule string
fields[key][display] {String|Function} fields[key][display] {String|Function}
fields[key][tip] {String} Custom tip message fields[key][tip] {String} Custom tip message
fields[key][ok] {String} Custom success message fields[key][ok] {String} Custom success message
fields[key][msg] {Object} Custom error message fields[key][msg] {Object} Custom error message
fields[key][msgStyle] {String} Custom message style fields[key][msgStyle] {String} Custom message style
fields[key][msgClass] {String} A className which added to message placeholder element fields[key][msgClass] {String} A className which added to message placeholder element
fields[key][msgWrapper] {String} Tag name of the message placeholder element fields[key][msgWrapper] {String} Tag name of the message placeholder element
fields[key][msgMaker] {Function} A function to custom message HTML fields[key][msgMaker] {Function} A function to custom message HTML
fields[key][dataFilter] {Function} A function to convert ajax results fields[key][dataFilter] {Function} A function to convert ajax results
fields[key][valid] {Function} A function triggered when field is valid fields[key][valid] {Function} A function triggered when field is valid
fields[key][invalid] {Function} A function triggered when field is invalid fields[key][invalid] {Function} A function triggered when field is invalid
fields[key][must] {Boolean} If set true, we always check the field even has remote checking fields[key][must] {Boolean} If set true, we always check the field even has remote checking
fields[key][timely] {Boolean} Whether to enable timely validation fields[key][timely] {Boolean} Whether to enable timely validation
fields[key][target] {jqSelector} Define placement of a message fields[key][target] {jqSelector} Define placement of a message
*/ */
$.fn.validator = function(options) { $.fn.validator = function(options) {
var that = this, var that = this,
@ -6865,10 +6865,10 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
var name = elem.nodeName.toLowerCase(); var name = elem.nodeName.toLowerCase();
return ( name === 'input' && !({submit: 1, button: 1, reset: 1, image: 1})[elem.type] || return ( name === 'input' && !({submit: 1, button: 1, reset: 1, image: 1})[elem.type] ||
name === 'select' || name === 'select' ||
name === 'textarea' || name === 'textarea' ||
elem.contentEditable === 'true' elem.contentEditable === 'true'
) && !elem.disabled; ) && !elem.disabled;
}, },
// any value, but not only whitespace // any value, but not only whitespace
filled: function(elem) { filled: function(elem) {
@ -7038,7 +7038,7 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
!key || !key ||
// If dataRule and element are diffrent from old's, we use ID mode. // If dataRule and element are diffrent from old's, we use ID mode.
(dataRule !== null && (field = me.fields[key]) && dataRule !== field.rule && el.id !== field.key) (dataRule !== null && (field = me.fields[key]) && dataRule !== field.rule && el.id !== field.key)
) )
) { ) {
key = '#' + el.id; key = '#' + el.id;
} }
@ -7463,7 +7463,7 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
// trigger event // trigger event
$(el).attr( ARIA_INVALID, isValid ? null : true ) $(el).attr( ARIA_INVALID, isValid ? null : true )
.trigger( callback + CLS_NS_FIELD, [ret, me] ); .trigger( callback + CLS_NS_FIELD, [ret, me] );
me.$el.triggerHandler('validation', [ret, me]); me.$el.triggerHandler('validation', [ret, me]);
if (me.checkOnly) return; if (me.checkOnly) return;
@ -8285,34 +8285,34 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
}); });
$(document) $(document)
.on('click', ':submit', function(){ .on('click', ':submit', function(){
var input = this, attrNode; var input = this, attrNode;
if (!input.form) return; if (!input.form) return;
// Shim for "formnovalidate" // Shim for "formnovalidate"
attrNode = input.getAttributeNode('formnovalidate'); attrNode = input.getAttributeNode('formnovalidate');
if (attrNode && attrNode.nodeValue !== null || attr(input, NOVALIDATE)!== null) { if (attrNode && attrNode.nodeValue !== null || attr(input, NOVALIDATE)!== null) {
novalidateonce = true; novalidateonce = true;
} }
}) })
// Automatic initializing form validation // Automatic initializing form validation
.on('focusin submit validate', 'form,.'+CLS_WRAPPER, function(e) { .on('focusin submit validate', 'form,.'+CLS_WRAPPER, function(e) {
if ( attr(this, NOVALIDATE) !== null ) return; if ( attr(this, NOVALIDATE) !== null ) return;
var $form = $(this), me; var $form = $(this), me;
if ( !$form.data(NS) && (me = _getInstance(this)) ) { if ( !$form.data(NS) && (me = _getInstance(this)) ) {
if ( !$.isEmptyObject(me.fields) ) { if ( !$.isEmptyObject(me.fields) ) {
// Execute event handler // Execute event handler
if (e.type === 'focusin') { if (e.type === 'focusin') {
me._focusin(e); me._focusin(e);
} else {
me._submit(e);
}
} else { } else {
attr(this, NOVALIDATE, NOVALIDATE); me._submit(e);
$form.off(CLS_NS).removeData(NS);
} }
} else {
attr(this, NOVALIDATE, NOVALIDATE);
$form.off(CLS_NS).removeData(NS);
} }
}); }
});
new Messages({ new Messages({
fallback: 'This field is not valid.', fallback: 'This field is not valid.',
@ -8327,11 +8327,11 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* required * required
* *
* @example: * @example:
required required
required(jqSelector) required(jqSelector)
required(anotherRule) required(anotherRule)
required(not, -1) required(not, -1)
required(from, .contact) required(from, .contact)
*/ */
required: function(element, params) { required: function(element, params) {
var me = this, var me = this,
@ -8391,11 +8391,11 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* integer * integer
* *
* @example: * @example:
integer integer
integer[+] integer[+]
integer[+0] integer[+0]
integer[-] integer[-]
integer[-0] integer[-0]
*/ */
integer: function(element, params) { integer: function(element, params) {
var re, z = '0|', var re, z = '0|',
@ -8427,15 +8427,15 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* match another field * match another field
* *
* @example: * @example:
match[password] Match the password field (two values must be the same) match[password] Match the password field (two values must be the same)
match[eq, password] Ditto match[eq, password] Ditto
match[neq, count] The value must be not equal to the value of the count field match[neq, count] The value must be not equal to the value of the count field
match[lt, count] The value must be less than the value of the count field match[lt, count] The value must be less than the value of the count field
match[lte, count] The value must be less than or equal to the value of the count field match[lte, count] The value must be less than or equal to the value of the count field
match[gt, count] The value must be greater than the value of the count field match[gt, count] The value must be greater than the value of the count field
match[gte, count] The value must be greater than or equal to the value of the count field match[gte, count] The value must be greater than or equal to the value of the count field
match[gte, startDate, date] match[gte, startDate, date]
match[gte, startTime, time] match[gte, startTime, time]
**/ **/
match: function(element, params) { match: function(element, params) {
if (!params) return; if (!params) return;
@ -8514,9 +8514,9 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* range numbers * range numbers
* *
* @example: * @example:
range[0~99] Number 0-99 range[0~99] Number 0-99
range[0~] Number greater than or equal to 0 range[0~] Number greater than or equal to 0
range[~100] Number less than or equal to 100 range[~100] Number less than or equal to 100
**/ **/
range: function(element, params) { range: function(element, params) {
return this.getRangeMsg(this.value, params); return this.getRangeMsg(this.value, params);
@ -8526,11 +8526,11 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* how many checkbox or radio inputs that checked * how many checkbox or radio inputs that checked
* *
* @example: * @example:
checked; no empty, same to required checked; no empty, same to required
checked[1~3] 1-3 items checked[1~3] 1-3 items
checked[1~] greater than 1 item checked[1~] greater than 1 item
checked[~3] less than 3 items checked[~3] less than 3 items
checked[3] 3 items checked[3] 3 items
**/ **/
checked: function(element, params) { checked: function(element, params) {
if ( !_checkable(element) ) return; if ( !_checkable(element) ) return;
@ -8560,10 +8560,10 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* length of a characters (You can pass the second parameter "true", will calculate the length in bytes) * length of a characters (You can pass the second parameter "true", will calculate the length in bytes)
* *
* @example: * @example:
length[6~16] 6-16 characters length[6~16] 6-16 characters
length[6~] Greater than 6 characters length[6~] Greater than 6 characters
length[~16] Less than 16 characters length[~16] Less than 16 characters
length[~16, true] Less than 16 characters, non-ASCII characters calculating two-character length[~16, true] Less than 16 characters, non-ASCII characters calculating two-character
**/ **/
length: function(element, params) { length: function(element, params) {
var value = this.value, var value = this.value,
@ -8578,20 +8578,20 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* @description * @description
* remote([get:]url [, name1, [name2 ...]]); * remote([get:]url [, name1, [name2 ...]]);
* Adaptation three kinds of results (Front for the successful, followed by a failure): * Adaptation three kinds of results (Front for the successful, followed by a failure):
1. text: 1. text:
'' 'Error Message' '' 'Error Message'
2. json: 2. json:
{"ok": ""} {"error": "Error Message"} {"ok": ""} {"error": "Error Message"}
3. json wrapper: 3. json wrapper:
{"status": 1, "data": {"ok": ""}} {"status": 1, "data": {"error": "Error Message"}} {"status": 1, "data": {"ok": ""}} {"status": 1, "data": {"error": "Error Message"}}
* @example * @example
The simplest: remote(path/to/server); The simplest: remote(path/to/server);
With parameters: remote(path/to/server, name1, name2, ...); With parameters: remote(path/to/server, name1, name2, ...);
By GET: remote(get:path/to/server, name1, name2, ...); By GET: remote(get:path/to/server, name1, name2, ...);
Name proxy: remote(path/to/server, name1, proxyname2:name2, proxyname3:#id3, ...) Name proxy: remote(path/to/server, name1, proxyname2:name2, proxyname3:#id3, ...)
Query String remote(path/to/server, foo=1&bar=2, name1, name2, ...) Query String remote(path/to/server, foo=1&bar=2, name1, name2, ...)
CORS remote(cors:path/to/server) CORS remote(cors:path/to/server)
JSONP remote(jsonp:path/to/server) JSONP remote(jsonp:path/to/server)
*/ */
remote: function(element, params) { remote: function(element, params) {
if (!params) return; if (!params) return;
@ -8695,8 +8695,8 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* @param {String|Object} name * @param {String|Object} name
* @param {Object} obj * @param {Object} obj
* @example * @example
.setTheme( themeName, themeOptions ) .setTheme( themeName, themeOptions )
.setTheme( multiThemes ) .setTheme( multiThemes )
*/ */
Validator.setTheme = function(name, obj) { Validator.setTheme = function(name, obj) {
if ( isObject(name) ) { if ( isObject(name) ) {
@ -8713,10 +8713,10 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
* @static load * @static load
* @param {String} str * @param {String} str
* @example * @example
.load('local=zh-CN') // load: local/zh-CN.js and jquery.validator.css .load('local=zh-CN') // load: local/zh-CN.js and jquery.validator.css
.load('local=zh-CN&css=') // load: local/zh-CN.js .load('local=zh-CN&css=') // load: local/zh-CN.js
.load('local&css') // load: local/en.js (set <html lang="en">) and jquery.validator.css .load('local&css') // load: local/en.js (set <html lang="en">) and jquery.validator.css
.load('local') // dito .load('local') // dito
*/ */
Validator.load = function(str) { Validator.load = function(str) {
if (!str) return; if (!str) return;
@ -8772,6 +8772,7 @@ define('upload',['jquery', 'bootstrap', 'plupload', 'template'], function ($, un
return $[NS] = Validator; return $[NS] = Validator;
})); }));
/********************************* /*********************************
* Themes, rules, and i18n support * Themes, rules, and i18n support
* Locale: Chinese; 中文 * Locale: Chinese; 中文
@ -9980,6 +9981,29 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
destroyallbtn: '.btn-destroyall', destroyallbtn: '.btn-destroyall',
dragsortfield: 'weigh', dragsortfield: 'weigh',
}, },
button: {
edit: {
name: 'edit',
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-success btn-editone'
},
del: {
name: 'del',
icon: 'fa fa-trash',
title: __('Del'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-danger btn-delone'
},
dragsort: {
name: 'dragsort',
icon: 'fa fa-arrows',
title: __('Drag to sort'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-primary btn-dragsort'
}
},
api: { api: {
init: function (defaults, columnDefaults, locales) { init: function (defaults, columnDefaults, locales) {
defaults = defaults ? defaults : {}; defaults = defaults ? defaults : {};
@ -10030,6 +10054,12 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
} }
Toastr.error(__('Unknown data format')); Toastr.error(__('Unknown data format'));
}); });
//当加载数据成功时
table.on('load-success.bs.table', function (e, data) {
if (typeof data.rows === 'undefined' && typeof data.code != 'undefined') {
Toastr.error(data.msg);
}
});
//当刷新表格时 //当刷新表格时
table.on('refresh.bs.table', function (e, settings, data) { table.on('refresh.bs.table', function (e, settings, data) {
$(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin"); $(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
@ -10481,32 +10511,14 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
names.push(item.name); names.push(item.name);
}); });
if (options.extend.dragsort_url !== '' && names.indexOf('dragsort') === -1) { if (options.extend.dragsort_url !== '' && names.indexOf('dragsort') === -1) {
buttons.push({ buttons.push(Table.button.dragsort);
name: 'dragsort',
icon: 'fa fa-arrows',
title: __('Drag to sort'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-primary btn-dragsort'
});
} }
if (options.extend.edit_url !== '' && names.indexOf('edit') === -1) { if (options.extend.edit_url !== '' && names.indexOf('edit') === -1) {
buttons.push({ Table.button.edit.url = options.extend.edit_url;
name: 'edit', buttons.push(Table.button.edit);
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-success btn-editone',
url: options.extend.edit_url
});
} }
if (options.extend.del_url !== '' && names.indexOf('del') === -1) { if (options.extend.del_url !== '' && names.indexOf('del') === -1) {
buttons.push({ buttons.push(Table.button.del);
name: 'del',
icon: 'fa fa-trash',
title: __('Del'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-danger btn-delone'
});
} }
return Table.api.buttonlink(this, buttons, value, row, index, 'operate'); return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
} }

View File

@ -72,6 +72,29 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
destroyallbtn: '.btn-destroyall', destroyallbtn: '.btn-destroyall',
dragsortfield: 'weigh', dragsortfield: 'weigh',
}, },
button: {
edit: {
name: 'edit',
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-success btn-editone'
},
del: {
name: 'del',
icon: 'fa fa-trash',
title: __('Del'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-danger btn-delone'
},
dragsort: {
name: 'dragsort',
icon: 'fa fa-arrows',
title: __('Drag to sort'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-primary btn-dragsort'
}
},
api: { api: {
init: function (defaults, columnDefaults, locales) { init: function (defaults, columnDefaults, locales) {
defaults = defaults ? defaults : {}; defaults = defaults ? defaults : {};
@ -122,6 +145,12 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
} }
Toastr.error(__('Unknown data format')); Toastr.error(__('Unknown data format'));
}); });
//当加载数据成功时
table.on('load-success.bs.table', function (e, data) {
if (typeof data.rows === 'undefined' && typeof data.code != 'undefined') {
Toastr.error(data.msg);
}
});
//当刷新表格时 //当刷新表格时
table.on('refresh.bs.table', function (e, settings, data) { table.on('refresh.bs.table', function (e, settings, data) {
$(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin"); $(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
@ -573,32 +602,14 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
names.push(item.name); names.push(item.name);
}); });
if (options.extend.dragsort_url !== '' && names.indexOf('dragsort') === -1) { if (options.extend.dragsort_url !== '' && names.indexOf('dragsort') === -1) {
buttons.push({ buttons.push(Table.button.dragsort);
name: 'dragsort',
icon: 'fa fa-arrows',
title: __('Drag to sort'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-primary btn-dragsort'
});
} }
if (options.extend.edit_url !== '' && names.indexOf('edit') === -1) { if (options.extend.edit_url !== '' && names.indexOf('edit') === -1) {
buttons.push({ Table.button.edit.url = options.extend.edit_url;
name: 'edit', buttons.push(Table.button.edit);
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-success btn-editone',
url: options.extend.edit_url
});
} }
if (options.extend.del_url !== '' && names.indexOf('del') === -1) { if (options.extend.del_url !== '' && names.indexOf('del') === -1) {
buttons.push({ buttons.push(Table.button.del);
name: 'del',
icon: 'fa fa-trash',
title: __('Del'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-danger btn-delone'
});
} }
return Table.api.buttonlink(this, buttons, value, row, index, 'operate'); return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
} }