2015-01-26 09:48:40 +00:00
|
|
|
<?php
|
|
|
|
$this->headTitle($this->config->title->site);
|
|
|
|
$this->headTitle('后台管理');
|
|
|
|
$this->headTitle()->setSeparator(' - ');
|
|
|
|
$theme = new Theme;
|
|
|
|
$theme->AppendPlus($this,"jquery-fileupload");
|
|
|
|
?>
|
|
|
|
<div class="row-fluid">
|
|
|
|
<div class="span2">
|
|
|
|
<?= $this->partial('data/left.phtml'); ?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="span10">
|
|
|
|
<h3>數據導入</h3>
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
<label>上傳文件,請選擇Excel文件進行上傳</label>
|
|
|
|
|
|
|
|
<span class="btn btn-success fileinput-button file-upload-ctls">上傳文件<input id="fileupload" type="file" name="FileData"></span>
|
2015-01-27 10:19:29 +00:00
|
|
|
<a href="javascript:void(0);" class="btn btn-info" id="ctl-show-files">查看已上傳的文件</a>
|
2015-01-26 09:48:40 +00:00
|
|
|
<div class="progress" id="pdf-upload-progress" style="display: none;">
|
|
|
|
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="uploadedFile"></div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
$(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var jqXHR = $('#fileupload').fileupload({
|
|
|
|
url: '/admin/data/dataimport/ac/upload',
|
|
|
|
dataType: 'json',
|
|
|
|
done: function (e, data) {
|
|
|
|
|
2015-01-27 10:19:29 +00:00
|
|
|
if(typeof(data.result.error) != 'undefined' && data.result.error != 0)
|
|
|
|
{
|
|
|
|
alert(data.result.error);
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-26 09:48:40 +00:00
|
|
|
|
2015-01-27 10:19:29 +00:00
|
|
|
if($('#uploadedFile').html() == "")
|
|
|
|
$('#uploadedFile').html(upload.makeFileHtml(data.result));
|
|
|
|
else
|
|
|
|
$('#uploadedFile').append(upload.makeFileHtml(data.result));
|
2015-01-26 09:48:40 +00:00
|
|
|
|
2015-01-27 10:19:29 +00:00
|
|
|
return true;
|
2015-01-26 09:48:40 +00:00
|
|
|
|
2015-01-27 10:19:29 +00:00
|
|
|
},
|
|
|
|
stop : function (e) {
|
|
|
|
$('#pdf-upload-progress').hide();
|
|
|
|
$('.file-upload-ctls').show();
|
|
|
|
},//stop
|
|
|
|
start : function (e) {
|
|
|
|
$('.file-upload-ctls').hide();
|
|
|
|
$('#pdf-upload-progress .progress-bar').css('width', 0 + '%');
|
|
|
|
$('#pdf-upload-progress').show();
|
|
|
|
},//start
|
|
|
|
progressall: function (e, data) {
|
|
|
|
var progress = parseInt(data.loaded / data.total * 100, 10);
|
|
|
|
$('#pdf-upload-progress .progress-bar').css(
|
|
|
|
'width',
|
|
|
|
progress + '%'
|
|
|
|
);
|
|
|
|
},//progressall
|
|
|
|
add: function (e, data) {
|
|
|
|
if($('input[name=attid]').length >= 1)
|
|
|
|
{
|
|
|
|
upload.deleteFile($('input[name=attid]').val());
|
|
|
|
$('file-alert').alert('close')
|
|
|
|
}
|
|
|
|
|
|
|
|
data.process().done(function () {
|
|
|
|
data.submit();
|
|
|
|
});
|
|
|
|
}//add
|
|
|
|
}).prop('disabled', !$.support.fileInput)
|
|
|
|
.parent().addClass($.support.fileInput ? undefined : 'disabled');
|
|
|
|
//file upload end
|
|
|
|
|
|
|
|
$('#ctl-show-files').click(function(){
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
'type':"POST",
|
|
|
|
'url':'/admin/data/dataimport/ac/files',
|
|
|
|
'data':'',
|
|
|
|
'success':function(data){
|
|
|
|
if (data!=null)
|
|
|
|
{
|
|
|
|
if($.isEmptyObject(data))
|
|
|
|
{
|
|
|
|
alert("目前沒有文件");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($('#uploadedFile').html() == "")
|
|
|
|
$('#uploadedFile').html(upload.makeFileList(data));
|
|
|
|
else
|
|
|
|
$('#uploadedFile').append(upload.makeFileList(data));
|
|
|
|
|
|
|
|
$('#ctl-show-files').attr('disabled','disabled');
|
|
|
|
$("#ctl-show-files").unbind( "click" );
|
|
|
|
}else{
|
|
|
|
alert('处理中出现错误');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'timeout': 30000
|
2015-01-26 09:48:40 +00:00
|
|
|
});
|
2015-01-27 10:19:29 +00:00
|
|
|
|
|
|
|
});//show files
|
2015-01-26 09:48:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var upload = {
|
|
|
|
makeFileHtml : function(data){
|
|
|
|
return '<div class="alert alert-success">'
|
2015-01-27 10:19:29 +00:00
|
|
|
+ '<span class="ctl-files">'+data.file+'</span>'
|
|
|
|
+ ' <a href="/admin/data/dataimport/ac/prepare/?file='+ encodeURI(data.file) +'">導入數據</a>'
|
|
|
|
+ '<a href="javascript:void(0)" onclick="upload.delete(this,\''+data.file+'\')" class="pull-right">刪除</a>'
|
2015-01-26 09:48:40 +00:00
|
|
|
+ "</div>";
|
2015-01-27 10:19:29 +00:00
|
|
|
},
|
|
|
|
makeFileList : function(data){
|
|
|
|
|
|
|
|
var li = [];
|
|
|
|
|
|
|
|
$.each(data,function(k,v){
|
|
|
|
li.push('<div class="alert alert-success ctl-files">'
|
|
|
|
+ '<span class="ctl-files">'+v+'</span>'
|
|
|
|
+ ' <a href="/admin/data/dataimport/ac/prepare/?file='+ encodeURI(v) +'">導入數據</a>'
|
|
|
|
+ '<a href="javascript:void(0);" onclick="upload.delete(this,\''+v+'\')" class="pull-right">刪除</a>'
|
|
|
|
+ "</div>");
|
|
|
|
});
|
|
|
|
|
|
|
|
return li.join("");
|
|
|
|
},
|
|
|
|
delete : function(dom,file){
|
|
|
|
$.ajax({
|
|
|
|
'type':"POST",
|
|
|
|
'url':'/admin/data/dataimport/ac/delete',
|
|
|
|
'data':'file='+file,
|
|
|
|
'success':function(data){
|
|
|
|
if(data.success == true)
|
|
|
|
$(dom).parent('div').remove();
|
|
|
|
else
|
|
|
|
alert("failed");
|
|
|
|
},
|
|
|
|
'timeout': 30000
|
|
|
|
});
|
2015-01-26 09:48:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|