Authored by 姜枫

add app hotfix config

/**
* 用户操作日志
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/8/22
*/
import {OperationLogger} from '../models';
const OperationLog = {
async action(user, action, description, meta) {
await OperationLogger.insert({
user: {
id: user._id,
username: user.username
},
action: action,
description: description,
meta: meta,
time: new Date()
});
}
};
export default OperationLog;
... ...
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/19
*/
'use strict';
import Model from './model';
class Hotfix extends Model {
constructor() {
super('hotfix');
}
}
export default Hotfix;
... ...
... ... @@ -6,6 +6,8 @@ import BuildingModel from './building';
import ProjectModel from './project';
import DeployModel from './deploy';
import UserModel from './user';
import HotfixModel from './hotfix';
import OperationLoggerModel from './operation_logger';
shelljs.mkdir('-p', config.dbDir);
... ... @@ -14,11 +16,17 @@ const Building = new BuildingModel();
const Project = new ProjectModel();
const DeployInfo = new DeployModel();
const User = new UserModel();
const Hotfix = new HotfixModel();
const OperationLogger = new OperationLoggerModel();
User.init();
export {
Server,
Building,
Project,
DeployInfo,
User
User,
Hotfix,
OperationLogger
};
\ No newline at end of file
... ...
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/22
*/
'use strict';
import Model from './model';
class OperationLogger extends Model {
constructor() {
super('operation_logger');
}
}
export default OperationLogger;
... ...
... ... @@ -7,12 +7,26 @@
'use strict';
import Model from './model';
import md5 from 'md5';
class User extends Model {
constructor() {
super('users');
}
async init() {
let count = await this.count({});
if (count === 0) {
await this.insert({
"username": "yoho",
"password": md5("yoho9646"),
"role": "1000",
"state": "1"
});
}
}
findByUsername(username) {
return this.findOne({
username: username
... ...
/**
* app hotfix 配置
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/8/19
*/
'use strict';
import Router from 'koa-router';
import md5File from 'md5-file';
import md5 from 'md5';
import {Hotfix} from '../../models';
import qn from '../../../lib/qiniu'
import path from 'path';
import Operation from '../../logger/operation';
let r = new Router();
const PRIVATE_KEY = 'fd4ad5fcsa0de589af23234ks1923ks';
const hf = {
async list_page(ctx) {
let type = ctx.params.type;
let hotfixs = await Hotfix.cfind({
type: type
}).sort({
time: -1
}).exec();
await ctx.render('action/hotfix_list', {hotfixs: hotfixs, type: type});
},
async new_page(ctx) {
let type = ctx.params.type;
await ctx.render('action/hotfix_form', {type: type});
},
async save(ctx) {
let type = ctx.params.type;
let body = ctx.request.body;
let {appName, appVersion, patchVersion, _files} = body;
let batchFile;
if (_files && _files.batch) {
batchFile = _files.batch;
} else {
return ctx.body = {
code: 400,
message: '未上传补丁文件'
};
}
let filecode = md5File.sync(batchFile.path);
let hotfixRaw = {
type: type,
appName: appName,
appVersion: appVersion,
patchVersion: patchVersion,
filecode: filecode,
time: new Date()
};
let batchKey = `app-hotfix2/${appName}/${type.toLowerCase()}/${appVersion}`;
if (patchVersion) {
batchKey = path.join(batchKey, patchVersion);
}
batchKey = path.join(batchKey, batchFile.name);
let apiFileKey = `app-hotfix2/${appName}/${type.toLowerCase()}/${appVersion}/api.json`;
let batchUpload = await qn.uploadFileAsync(batchFile.path, {key: batchKey});
if (batchUpload && batchUpload.url) {
let apiData = {
data: {
url: batchUpload.url,
patchv: patchVersion,
filecode: md5(filecode + 'yohopatch2016')
}
};
hotfixRaw.patchFile = batchUpload.url;
apiData.md5 = md5(PRIVATE_KEY + ':' + JSON.stringify(apiData.data));
console.log(apiFileKey);
let apiUpload = await qn.key(apiFileKey).uploadAsync(JSON.stringify(apiData), {key: apiFileKey});
if (apiUpload && apiUpload.url) {
hotfixRaw.apiFile = apiUpload.url;
} else {
return ctx.body = {
code: 400,
message: '上传api文件失败, 请重试'
};
}
} else {
return ctx.body = {
code: 400,
message: '上传补丁文件失败, 请重试'
};
}
await Hotfix.insert(hotfixRaw);
Operation.action(ctx.session.user, 'NEW_HOTFIX', '新增hotfix', {
type: type,
appName: appName,
appVersion: appVersion,
batchFile: hotfixRaw.patchFile
});
return ctx.body = {
code: 200
};
}
};
r.get('/:type', hf.list_page);
r.get('/new/:type', hf.new_page);
r.post('/save/:type', hf.save);
export default r;
... ...
... ... @@ -3,6 +3,7 @@
import Router from 'koa-router';
import md5 from 'md5';
import {User} from '../../models';
import Operation from '../../logger/operation';
let r = new Router();
... ... @@ -20,6 +21,8 @@ const login = {
ctx.session = {
user: user
};
Operation.action(user, 'LOGIN', '用户登陆');
ctx.redirect('/projects');
ctx.status = 301;
} else {
... ... @@ -29,8 +32,9 @@ const login = {
},
logout: (ctx, next) => {
ctx.session = null;
ctx.redirect('/');
ctx.status = 301;
console.log('logout!');
ctx.set('Cache-Control', 'no-cache');
ctx.redirect('/projects');
}
};
... ...
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/22
*/
'use strict';
import Router from 'koa-router';
import {
OperationLogger
} from '../../models';
const r = new Router();
r.get('/log', async (ctx) => {
await ctx.render('action/operation_log');
});
r.get('/log/query', async (ctx) => {
console.log(ctx.query);
});
export default r;
... ...
... ... @@ -4,7 +4,7 @@ import Router from 'koa-router';
import moment from 'moment';
import Build from '../../ci/build';
import Deploy from '../../ci/deploy';
import Operation from '../../logger/operation';
import {
Building,
... ... @@ -38,7 +38,7 @@ const p = {
/**
* 单个项目首页
*/
project_index: async (ctx, next) => {
project_index: async(ctx, next) => {
let id = ctx.params.id;
let env = ctx.request.query.env;
let project = await Project.findById(id);
... ... @@ -123,8 +123,10 @@ const p = {
}, {
$set: project
});
await Operation.action(ctx.session.user, 'EDIT_PROJECT_INFO', '修改项目信息', {_id: id, name: project.name});
} else {
await Project.insert(project);
await Operation.action(ctx.session.user, 'NEW_PROJECT_INFO', '新增项目信息', {_id: id, name: project.name});
}
ctx.redirect('/projects');
ctx.status = 301;
... ... @@ -171,6 +173,9 @@ const p = {
let id = buildingDoc[0]._id;
build.run(id);
await Operation.action(ctx.session.user, 'NEW_PROJECT_BUILDING', '新增项目构建', {_id: id, project: p.name, branch: branch, env: env});
ctx.body = {
code: 200,
id: id
... ... @@ -201,6 +206,9 @@ const p = {
let deploy = new Deploy(project, building);
deploy.deploy(info);
});
await Operation.action(ctx.session.user, 'PROJECT_DEPLOY', '项目分发部署', {_id: buildingId, project: project.name, branch: building.branch, env: building.env});
ctx.body = {
code: 200,
building: building
... ...
... ... @@ -2,6 +2,7 @@
import Router from 'koa-router';
import Operation from '../../logger/operation';
import {
Server
} from '../../models';
... ... @@ -48,15 +49,21 @@ const servers = {
}, {
$set: server
});
await Operation.action(ctx.session.user, 'EDIT_SERVER', '修改服务器配置', {_id: _id, host: host});
} else {
await Server.insert(server);
await Operation.action(ctx.session.user, 'NEW_SERVER', '新增服务器配置', {_id: _id, host: host});
}
ctx.redirect('/servers/setting');
ctx.status = 301;
},
del: async(ctx, next) => {
let id = ctx.request.body.id;
let server = await Server.findById(id);
await Server.removeById(id);
await Operation.action(ctx.session.user, 'DELETE_SERVER', '删除服务器配置', {_id: id, host: server.host});
ctx.body = {
code: 200
};
... ...
... ... @@ -8,6 +8,7 @@
import Router from 'koa-router';
import md5 from 'md5';
import {User} from '../../models';
import Operation from '../../logger/operation';
const r = new Router;
... ... @@ -47,15 +48,20 @@ const user = {
}, {
$set: user
});
await Operation.action(ctx.session.user, 'EDIT_USER', '修改用户', {_id: _id, username: user.username});
} else {
await User.insert(user);
await Operation.action(ctx.session.user, 'NEW_USER', '新增用户', {_id: _id, username: user.username});
}
ctx.redirect('/users/setting');
ctx.status = 301;
},
async del(ctx) {
let id = ctx.request.body.id;
let u = await User.findById(id);
await User.removeById(id);
await Operation.action(ctx.session.user, 'DELETE_USER', '删除用户', {_id: id, username: u.username});
ctx.body = {
code: 200
};
... ...
... ... @@ -7,6 +7,8 @@ import servers from './actions/servers';
import login from './actions/login';
import monitor from './actions/monitor';
import users from './actions/users';
import hotfix from './actions/hotfix';
import operationLog from './actions/operation_log';
const noAuth = new Router();
const base = new Router();
... ... @@ -30,6 +32,8 @@ export default function (app) {
base.use('/servers', servers.routes(), servers.allowedMethods());
base.use('/monitor', monitor.routes(), monitor.allowedMethods());
base.use('/users', users.routes(), users.allowedMethods());
base.use('/hotfix', hotfix.routes(), hotfix.allowedMethods());
base.use('/operation', operationLog.routes(), operationLog.allowedMethods());
base.use('', index.routes(), index.allowedMethods());
... ...
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">Hotfix</a></li>
<li>{{type}}</li>
</ul>
<h4>新增补丁信息</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="panel panel-default">
<div class="panel-heading">
<p>&nbsp;</p>
</div>
<form id="hotfix-form" action="/hotfix/save/{{type}}" method="POST" enctype="multipart/form-data" data-pjax>
<input type="hidden" name="_id" value="{{_id}}">
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">App名称</label>
<select id="appName" name="appName" data-placeholder="Choose a Host..." class="form-control" style="height: 40px;">
<option value="yohobuy">yohobuy</option>
</select>
</div>
<!-- form-group -->
</div>
<!-- col-sm-6 -->
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">App版本</label>
<input type="text" name="appVersion" value="{{appVersion}}" class="form-control" placeholder="App version. (必填)">
</div>
<!-- form-group -->
</div>
<!-- col-sm-6 -->
</div>
<!-- row -->
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">补丁版本</label>
<input type="text" name="patchVersion" value="{{patchVersion}}" class="form-control" placeholder="patch version (可为空)">
</div>
<!-- form-group -->
</div>
<!-- col-sm-6 -->
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">补丁文件</label>
<input type="file" name="batch" class="form-control" placeholder="upload the patch file (必填)">
</div>
<!-- form-group -->
</div>
</div>
<!-- row -->
</div>
<!-- panel-body -->
<div class="panel-footer">
<button type="submit" class="btn btn-primary">保存</button>
<button type="button" class="btn btn-default ml20 go-back">取消</button>
</div>
</form>
<!-- panel-footer -->
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">参数说明</h4>
</div><!-- panel-heading -->
<div class="panel-body">
<div class="alert alert-danger">App版本必须和调用接口时app_version一致</div>
</div>
</div>
<script>
$(function(){
// $('#hotfix-form').off().on('submit', function(event) {
// event.preventDefault(); // stop default submit behavior
// $.pjax.submit(event, '#pjax-container', {
// type: 'POST',
// dataType: 'json',
// push: false
// });
// }).on('pjax:success', function(e, data) {
// console.log(111)
// return false;
// });
// $('#appName').select2();
$('#hotfix-form').ajaxForm(function(d) {
if (d && d.code === 200) {
$.pjax({
url: '/hotfix/{{type}}',
container: '#pjax-container'
});
} else {
alert(d.message);
}
});
$('.go-back').click(function() {
window.history.go(-1);
});
});
</script>
... ...
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">Hotfix</a></li>
<li>{{type}}</li>
</ul>
<h4>Hotfix</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel">
<div class="panel panel-primary-head">
<div class="panel-heading">
<div class="pull-right">
<a id="new-page" href="/hotfix/new/{{type}}" class="btn btn-success btn-rounded"><i class="glyphicon glyphicon-plus"></i> 新增Hotfix</a>
</div>
<h4 class="panel-title">{{type}} hotfix</h4>
<p>&nbsp;</p>
</div>
<!-- panel-heading -->
<table id="basicTable" class="table table-striped table-bordered responsive">
<thead class="">
<tr>
<th>App名称</th>
<th>App版本</th>
<th>补丁版本</th>
<th>文件MD5</th>
<th>接口文件</th>
<th>补丁文件</th>
</tr>
</thead>
<tbody>
{{#each hotfixs}}
<tr>
<td>{{appName}}</td>
<td>{{appVersion}}</td>
<td>{{patchVersion}}</td>
<td>{{filecode}}</td>
<td>{{apiFile}}</td>
<td>{{patchFile}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<!-- panel -->
</div>
<script>
$(function() {
$("#basicTable").DataTable({
responsive: true,
pageLength: 25
});
$(document).pjax('#new-page', '#pjax-container')
});
</script>
\ No newline at end of file
... ...
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="/servers">系统管理</a></li>
<li>操作日志</li>
</ul>
<h4>所有用户数据操作日志</h4>
</div>
</div>
<!-- media -->
</div>
<div class="contentpanel project-index-page">
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right">
<a href="" class="tooltips panel-minimize"><i class="fa fa-minus"></i></a>
</div>
<h4 class="panel-title">操作日志</h4>
</div>
<div class="panel-body">
<table id="table-log" class="table table-striped table-bordered building-table">
<thead>
<tr>
<th>操作用户</th>
<th>时间</th>
<th>动作</th>
<th>描述</th>
<th>数据</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<script>
$(function() {
var tables = {};
$('.building-table').each(function() {
var env = $(this).parents('.panel').data('env');
tables[env] = $(this).DataTable({
responsive: true,
ajax: '/operation/log/query',
columns: [
{data: "username"},
{data: "time"},
{data: "action"},
{data: "description"},
{data: "meta"}
],
order: [[1, 'desc']]
});
});
});
</script>
\ No newline at end of file
... ...
... ... @@ -51,7 +51,7 @@
<script src="/js/pace.min.js"></script>
<script src="/js/retina.min.js"></script>
<script src="/js/jquery.cookies.js"></script>
<script src="/js/jquery.form.min.js"></script>
<script src="/js/flot/jquery.flot.min.js"></script>
<script src="/js/flot/jquery.flot.resize.min.js"></script>
<script src="/js/flot/jquery.flot.spline.min.js"></script>
... ...
... ... @@ -14,16 +14,23 @@
<ul class="nav nav-pills nav-stacked nav-menu">
<li class="active"><a href="/index"><i class="fa fa-home"></i> <span>Dashboard</span></a></li>
<li><a href="/projects"><i class="glyphicon glyphicon-th"></i> <span>项目</span></a></li>
<li class="parent"><a href=""><i class="fa fa-gears"></i> <span>监控中心</span></a>
<li class="parent"><a href=""><i class="glyphicon glyphicon-wrench"></i> <span>APP Hotfix</span></a>
<ul class="children">
<li><a href="/hotfix/Android">Android</a></li>
<li><a href="/hotfix/iOS">iOS</a></li>
</ul>
</li>
<li class="parent"><a href=""><i class="fa fa-eye"></i> <span>监控中心</span></a>
<ul class="children">
<li><a href="/monitor/log">实时日志</a></li>
</ul>
</li>
{{#if is_master}}
<li class="parent"><a href=""><i class="fa fa-gears"></i> <span>系统配置</span></a>
<li class="parent"><a href=""><i class="fa fa-gears"></i> <span>系统管理</span></a>
<ul class="children">
<li><a href="/servers/setting">服务器配置</a></li>
<li><a href="/users/setting">用户管理</a></li>
<li><a href="/operation/log">操作记录</a></li>
</ul>
</li>
{{/if}}
... ...
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/19
*/
'use strict';
import qn from 'qn';
import Promise from 'bluebird';
import _ from 'lodash';
const config = {
accessKey: 'cY9B5ZgON_7McTS5zV5nTeRyQ98MOcVD7W4eGVbE',
secretKey: 'RduqgmK7cAtaQvdIa1ax_zzmMsnv9ac-Ka0uF6wG',
origin: 'http://cdn.yoho.cn',
bucket: 'yohocdn'
};
const _default = Promise.promisifyAll(qn.create(config));
_default.key = function(key) {
let _conifg = _.clone(config);
_conifg.bucket = _conifg.bucket + ":" + key;
return Promise.promisifyAll(qn.create(_conifg));
};
export default _default;
... ...
... ... @@ -84,7 +84,7 @@ function formy(ctx, opts) {
form
.on('end', function() {
fields = qs.parse(fieldsArray.join('&'));
if (!Object.keys(files).length === 0) {
if (Object.keys(files).length !== 0) {
fields._files = files;
}
done(null, fields);
... ... @@ -100,7 +100,7 @@ function formy(ctx, opts) {
// fields[field] = [fields[field], value];
// }
// } else {
//
// fields[field] = value;
// }
fieldsArray.push(field + '=' + value);
... ...
... ... @@ -32,6 +32,7 @@
"author": "jiangfeng <jeff.jiang@yoho.cn>",
"license": "ISC",
"dependencies": {
"bluebird": "^3.4.1",
"co": "^4.6.0",
"co-body": "^4.2.0",
"formidable": "^1.0.17",
... ... @@ -48,9 +49,11 @@
"koa-static": "^3.0.0",
"lodash": "^4.13.1",
"md5": "^2.1.0",
"md5-file": "^3.1.1",
"moment": "^2.13.0",
"nedb": "^1.8.0",
"nedb-promise": "^2.0.0",
"qn": "^1.3.0",
"qs": "^6.2.0",
"shelljs": "^0.7.0",
"socket.io": "^1.4.6",
... ...
/*!
* jQuery Form Plugin
* version: 3.51.0-2014.06.20
* Requires jQuery v1.5 or later
* Copyright (c) 2014 M. Alsup
* Examples and documentation at: http://malsup.com/jquery/form/
* Project repository: https://github.com/malsup/form
* Dual licensed under the MIT and GPL licenses.
* https://github.com/malsup/form#copyright-and-license
*/
!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("undefined"!=typeof jQuery?jQuery:window.Zepto)}(function(e){"use strict";function t(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).ajaxSubmit(r))}function r(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=this;if(i.clk=r,"image"==r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function a(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}var n={};n.fileapi=void 0!==e("<input type='file'/>").get(0).files,n.formdata=void 0!==window.FormData;var i=!!e.fn.prop;e.fn.attr2=function(){if(!i)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t){function r(r){var a,n,i=e.param(r,t.traditional).split("&"),o=i.length,s=[];for(a=0;o>a;a++)i[a]=i[a].replace(/\+/g," "),n=i[a].split("="),s.push([decodeURIComponent(n[0]),decodeURIComponent(n[1])]);return s}function o(a){for(var n=new FormData,i=0;i<a.length;i++)n.append(a[i].name,a[i].value);if(t.extraData){var o=r(t.extraData);for(i=0;i<o.length;i++)o[i]&&n.append(o[i][0],o[i][1])}t.data=null;var s=e.extend(!0,{},e.ajaxSettings,t,{contentType:!1,processData:!1,cache:!1,type:u||"POST"});t.uploadProgress&&(s.xhr=function(){var r=e.ajaxSettings.xhr();return r.upload&&r.upload.addEventListener("progress",function(e){var r=0,a=e.loaded||e.position,n=e.total;e.lengthComputable&&(r=Math.ceil(a/n*100)),t.uploadProgress(e,a,n,r)},!1),r}),s.data=null;var c=s.beforeSend;return s.beforeSend=function(e,r){r.data=t.formData?t.formData:n,c&&c.call(this,e,r)},e.ajax(s)}function s(r){function n(e){var t=null;try{e.contentWindow&&(t=e.contentWindow.document)}catch(r){a("cannot get iframe.contentWindow document: "+r)}if(t)return t;try{t=e.contentDocument?e.contentDocument:e.document}catch(r){a("cannot get iframe.contentDocument: "+r),t=e.document}return t}function o(){function t(){try{var e=n(g).readyState;a("state = "+e),e&&"uninitialized"==e.toLowerCase()&&setTimeout(t,50)}catch(r){a("Server abort: ",r," (",r.name,")"),s(k),j&&clearTimeout(j),j=void 0}}var r=f.attr2("target"),i=f.attr2("action"),o="multipart/form-data",c=f.attr("enctype")||f.attr("encoding")||o;w.setAttribute("target",p),(!u||/post/i.test(u))&&w.setAttribute("method","POST"),i!=m.url&&w.setAttribute("action",m.url),m.skipEncodingOverride||u&&!/post/i.test(u)||f.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),m.timeout&&(j=setTimeout(function(){T=!0,s(D)},m.timeout));var l=[];try{if(m.extraData)for(var d in m.extraData)m.extraData.hasOwnProperty(d)&&l.push(e.isPlainObject(m.extraData[d])&&m.extraData[d].hasOwnProperty("name")&&m.extraData[d].hasOwnProperty("value")?e('<input type="hidden" name="'+m.extraData[d].name+'">').val(m.extraData[d].value).appendTo(w)[0]:e('<input type="hidden" name="'+d+'">').val(m.extraData[d]).appendTo(w)[0]);m.iframeTarget||v.appendTo("body"),g.attachEvent?g.attachEvent("onload",s):g.addEventListener("load",s,!1),setTimeout(t,15);try{w.submit()}catch(h){var x=document.createElement("form").submit;x.apply(w)}}finally{w.setAttribute("action",i),w.setAttribute("enctype",c),r?w.setAttribute("target",r):f.removeAttr("target"),e(l).remove()}}function s(t){if(!x.aborted&&!F){if(M=n(g),M||(a("cannot access response document"),t=k),t===D&&x)return x.abort("timeout"),void S.reject(x,"timeout");if(t==k&&x)return x.abort("server abort"),void S.reject(x,"error","server abort");if(M&&M.location.href!=m.iframeSrc||T){g.detachEvent?g.detachEvent("onload",s):g.removeEventListener("load",s,!1);var r,i="success";try{if(T)throw"timeout";var o="xml"==m.dataType||M.XMLDocument||e.isXMLDoc(M);if(a("isXml="+o),!o&&window.opera&&(null===M.body||!M.body.innerHTML)&&--O)return a("requeing onLoad callback, DOM not available"),void setTimeout(s,250);var u=M.body?M.body:M.documentElement;x.responseText=u?u.innerHTML:null,x.responseXML=M.XMLDocument?M.XMLDocument:M,o&&(m.dataType="xml"),x.getResponseHeader=function(e){var t={"content-type":m.dataType};return t[e.toLowerCase()]},u&&(x.status=Number(u.getAttribute("status"))||x.status,x.statusText=u.getAttribute("statusText")||x.statusText);var c=(m.dataType||"").toLowerCase(),l=/(json|script|text)/.test(c);if(l||m.textarea){var f=M.getElementsByTagName("textarea")[0];if(f)x.responseText=f.value,x.status=Number(f.getAttribute("status"))||x.status,x.statusText=f.getAttribute("statusText")||x.statusText;else if(l){var p=M.getElementsByTagName("pre")[0],h=M.getElementsByTagName("body")[0];p?x.responseText=p.textContent?p.textContent:p.innerText:h&&(x.responseText=h.textContent?h.textContent:h.innerText)}}else"xml"==c&&!x.responseXML&&x.responseText&&(x.responseXML=X(x.responseText));try{E=_(x,c,m)}catch(y){i="parsererror",x.error=r=y||i}}catch(y){a("error caught: ",y),i="error",x.error=r=y||i}x.aborted&&(a("upload aborted"),i=null),x.status&&(i=x.status>=200&&x.status<300||304===x.status?"success":"error"),"success"===i?(m.success&&m.success.call(m.context,E,"success",x),S.resolve(x.responseText,"success",x),d&&e.event.trigger("ajaxSuccess",[x,m])):i&&(void 0===r&&(r=x.statusText),m.error&&m.error.call(m.context,x,i,r),S.reject(x,"error",r),d&&e.event.trigger("ajaxError",[x,m,r])),d&&e.event.trigger("ajaxComplete",[x,m]),d&&!--e.active&&e.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,x,i),F=!0,m.timeout&&clearTimeout(j),setTimeout(function(){m.iframeTarget?v.attr("src",m.iframeSrc):v.remove(),x.responseXML=null},100)}}}var c,l,m,d,p,v,g,x,y,b,T,j,w=f[0],S=e.Deferred();if(S.abort=function(e){x.abort(e)},r)for(l=0;l<h.length;l++)c=e(h[l]),i?c.prop("disabled",!1):c.removeAttr("disabled");if(m=e.extend(!0,{},e.ajaxSettings,t),m.context=m.context||m,p="jqFormIO"+(new Date).getTime(),m.iframeTarget?(v=e(m.iframeTarget),b=v.attr2("name"),b?p=b:v.attr2("name",p)):(v=e('<iframe name="'+p+'" src="'+m.iframeSrc+'" />'),v.css({position:"absolute",top:"-1000px",left:"-1000px"})),g=v[0],x={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";a("aborting upload... "+r),this.aborted=1;try{g.contentWindow.document.execCommand&&g.contentWindow.document.execCommand("Stop")}catch(n){}v.attr("src",m.iframeSrc),x.error=r,m.error&&m.error.call(m.context,x,r,t),d&&e.event.trigger("ajaxError",[x,m,r]),m.complete&&m.complete.call(m.context,x,r)}},d=m.global,d&&0===e.active++&&e.event.trigger("ajaxStart"),d&&e.event.trigger("ajaxSend",[x,m]),m.beforeSend&&m.beforeSend.call(m.context,x,m)===!1)return m.global&&e.active--,S.reject(),S;if(x.aborted)return S.reject(),S;y=w.clk,y&&(b=y.name,b&&!y.disabled&&(m.extraData=m.extraData||{},m.extraData[b]=y.value,"image"==y.type&&(m.extraData[b+".x"]=w.clk_x,m.extraData[b+".y"]=w.clk_y)));var D=1,k=2,A=e("meta[name=csrf-token]").attr("content"),L=e("meta[name=csrf-param]").attr("content");L&&A&&(m.extraData=m.extraData||{},m.extraData[L]=A),m.forceSync?o():setTimeout(o,10);var E,M,F,O=50,X=e.parseXML||function(e,t){return window.ActiveXObject?(t=new ActiveXObject("Microsoft.XMLDOM"),t.async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!=t.documentElement.nodeName?t:null},C=e.parseJSON||function(e){return window.eval("("+e+")")},_=function(t,r,a){var n=t.getResponseHeader("content-type")||"",i="xml"===r||!r&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&("json"===r||!r&&n.indexOf("json")>=0?o=C(o):("script"===r||!r&&n.indexOf("javascript")>=0)&&e.globalEval(o)),o};return S}if(!this.length)return a("ajaxSubmit: skipping submit process - no element selected"),this;var u,c,l,f=this;"function"==typeof t?t={success:t}:void 0===t&&(t={}),u=t.type||this.attr2("method"),c=t.url||this.attr2("action"),l="string"==typeof c?e.trim(c):"",l=l||window.location.href||"",l&&(l=(l.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:l,success:e.ajaxSettings.success,type:u||e.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var m={};if(this.trigger("form-pre-serialize",[this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&t.beforeSerialize(this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var d=t.traditional;void 0===d&&(d=e.ajaxSettings.traditional);var p,h=[],v=this.formToArray(t.semantic,h);if(t.data&&(t.extraData=t.data,p=e.param(t.data,d)),t.beforeSubmit&&t.beforeSubmit(v,this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[v,this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var g=e.param(v,d);p&&(g=g?g+"&"+p:p),"GET"==t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+g,t.data=null):t.data=g;var x=[];if(t.resetForm&&x.push(function(){f.resetForm()}),t.clearForm&&x.push(function(){f.clearForm(t.includeHidden)}),!t.dataType&&t.target){var y=t.success||function(){};x.push(function(r){var a=t.replaceTarget?"replaceWith":"html";e(t.target)[a](r).each(y,arguments)})}else t.success&&x.push(t.success);if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=x.length;o>i;i++)x[i].apply(n,[e,r,a||f,f])},t.error){var b=t.error;t.error=function(e,r,a){var n=t.context||this;b.apply(n,[e,r,a,f])}}if(t.complete){var T=t.complete;t.complete=function(e,r){var a=t.context||this;T.apply(a,[e,r,f])}}var j=e("input[type=file]:enabled",this).filter(function(){return""!==e(this).val()}),w=j.length>0,S="multipart/form-data",D=f.attr("enctype")==S||f.attr("encoding")==S,k=n.fileapi&&n.formdata;a("fileAPI :"+k);var A,L=(w||D)&&!k;t.iframe!==!1&&(t.iframe||L)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){A=s(v)}):A=s(v):A=(w||D)&&k?o(v):e.ajax(t),f.removeData("jqxhr").data("jqxhr",A);for(var E=0;E<h.length;E++)h[E]=null;return this.trigger("form-submit-notify",[this,t]),this},e.fn.ajaxForm=function(n){if(n=n||{},n.delegation=n.delegation&&e.isFunction(e.fn.on),!n.delegation&&0===this.length){var i={s:this.selector,c:this.context};return!e.isReady&&i.s?(a("DOM not ready, queuing ajaxForm"),e(function(){e(i.s,i.c).ajaxForm(n)}),this):(a("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return n.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",this.selector,r).on("submit.form-plugin",this.selector,n,t).on("click.form-plugin",this.selector,n,r),this):this.ajaxFormUnbind().bind("submit.form-plugin",n,t).bind("click.form-plugin",n,r)},e.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,r){var a=[];if(0===this.length)return a;var i,o=this[0],s=this.attr("id"),u=t?o.getElementsByTagName("*"):o.elements;if(u&&!/MSIE [678]/.test(navigator.userAgent)&&(u=e(u).get()),s&&(i=e(':input[form="'+s+'"]').get(),i.length&&(u=(u||[]).concat(i))),!u||!u.length)return a;var c,l,f,m,d,p,h;for(c=0,p=u.length;p>c;c++)if(d=u[c],f=d.name,f&&!d.disabled)if(t&&o.clk&&"image"==d.type)o.clk==d&&(a.push({name:f,value:e(d).val(),type:d.type}),a.push({name:f+".x",value:o.clk_x},{name:f+".y",value:o.clk_y}));else if(m=e.fieldValue(d,!0),m&&m.constructor==Array)for(r&&r.push(d),l=0,h=m.length;h>l;l++)a.push({name:f,value:m[l]});else if(n.fileapi&&"file"==d.type){r&&r.push(d);var v=d.files;if(v.length)for(l=0;l<v.length;l++)a.push({name:f,value:v[l],type:d.type});else a.push({name:f,value:"",type:d.type})}else null!==m&&"undefined"!=typeof m&&(r&&r.push(d),a.push({name:f,value:m,type:d.type,required:d.required}));if(!t&&o.clk){var g=e(o.clk),x=g[0];f=x.name,f&&!x.disabled&&"image"==x.type&&(a.push({name:f,value:g.val()}),a.push({name:f+".x",value:o.clk_x},{name:f+".y",value:o.clk_y}))}return a},e.fn.formSerialize=function(t){return e.param(this.formToArray(t))},e.fn.fieldSerialize=function(t){var r=[];return this.each(function(){var a=this.name;if(a){var n=e.fieldValue(this,t);if(n&&n.constructor==Array)for(var i=0,o=n.length;o>i;i++)r.push({name:a,value:n[i]});else null!==n&&"undefined"!=typeof n&&r.push({name:this.name,value:n})}}),e.param(r)},e.fn.fieldValue=function(t){for(var r=[],a=0,n=this.length;n>a;a++){var i=this[a],o=e.fieldValue(i,t);null===o||"undefined"==typeof o||o.constructor==Array&&!o.length||(o.constructor==Array?e.merge(r,o):r.push(o))}return r},e.fieldValue=function(t,r){var a=t.name,n=t.type,i=t.tagName.toLowerCase();if(void 0===r&&(r=!0),r&&(!a||t.disabled||"reset"==n||"button"==n||("checkbox"==n||"radio"==n)&&!t.checked||("submit"==n||"image"==n)&&t.form&&t.form.clk!=t||"select"==i&&-1==t.selectedIndex))return null;if("select"==i){var o=t.selectedIndex;if(0>o)return null;for(var s=[],u=t.options,c="select-one"==n,l=c?o+1:u.length,f=c?o:0;l>f;f++){var m=u[f];if(m.selected){var d=m.value;if(d||(d=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),c)return d;s.push(d)}}return s}return e(t).val()},e.fn.clearForm=function(t){return this.each(function(){e("input,select,textarea",this).clearFields(t)})},e.fn.clearFields=e.fn.clearInputs=function(t){var r=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var a=this.type,n=this.tagName.toLowerCase();r.test(a)||"textarea"==n?this.value="":"checkbox"==a||"radio"==a?this.checked=!1:"select"==n?this.selectedIndex=-1:"file"==a?/MSIE/.test(navigator.userAgent)?e(this).replaceWith(e(this).clone(!0)):e(this).val(""):t&&(t===!0&&/hidden/.test(a)||"string"==typeof t&&e(this).is(t))&&(this.value="")})},e.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},e.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},e.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var r=this.type;if("checkbox"==r||"radio"==r)this.checked=t;else if("option"==this.tagName.toLowerCase()){var a=e(this).parent("select");t&&a[0]&&"select-one"==a[0].type&&a.find("option").selected(!1),this.selected=t}})},e.fn.ajaxSubmit.debug=!1});
\ No newline at end of file
... ...