+ add the feature of export 2 csv.

This commit is contained in:
wangchunsheng
2010-04-15 06:28:55 +00:00
parent 1bcc0fd1f3
commit b40cc408ec
19 changed files with 464 additions and 14 deletions

View File

@@ -278,6 +278,18 @@ class html
{
return " <input type='button' value='$label' class='button-c' $misc onclick='location.href=\"$link\"' /> ";
}
/**
* create a export link.
*
* @static
* @access public
* @return string the reset button tag.
*/
public static function export2csv($label = '', $pluginTitle, $misc = '')
{
return "<a href='#' onclick=\"$('.datatable').table2CSV({title:'$pluginTitle'})\" $misc />$label</a>\n<div id='exporter' class='hidden'></div>\n";
}
}
class js

View File

@@ -25,6 +25,7 @@
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/treeview.html.php';?>
<?php include '../../common/view/colorize.html.php';?>
<?php include '../../common/view/table2csv.html.php';?>
<script language='Javascript'>
/* 通过模块浏览。*/
function browseByModule(active)
@@ -65,6 +66,7 @@ function browseBySearch(active)
?>
</div>
<div class='f-right'>
<?php echo html::export2csv($lang->exportCSV, $lang->setFileName);?>
<?php common::printLink('bug', 'report', "productID=$productID&browseType=$browseType&moduleID=$moduleID", $lang->bug->report->common); ?>
<?php common::printLink('bug', 'create', "productID=$productID&extra=moduleID=$moduleID", $lang->bug->create); ?>
</div>
@@ -77,7 +79,7 @@ function browseBySearch(active)
<div class="yui-main">
<div class="yui-b">
<?php $vars = "productID=$productID&browseType=$browseType&param=$param&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}"; ?>
<table class='table-1 fixed colored tablesorter'>
<table class='table-1 fixed colored tablesorter datatable'>
<thead>
<tr class='colhead'>
<th class='w-id'> <?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>

View File

@@ -46,6 +46,8 @@ $lang->close = '关闭';
$lang->link = '关联';
$lang->unlink = '移除';
$lang->import = '导入';
$lang->exportCSV = '导出csv';
$lang->setFileName = '请输入文件名:';
$lang->activate = '激活';
$lang->save = '保存';
$lang->confirm = '确认';

View File

@@ -37,4 +37,18 @@ class file extends control
if(file_exists($file->realPath))$this->locate($file->webPath);
$this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true);
}
/* 导出csv格式的文件。*/
public function export2csv($agent)
{
$fileName = $this->post->fileName;
if(strpos($fileName, '.csv') === false) $fileName .= '.csv';
if($agent == 'ie') $fileName = urlencode($fileName);
header('Content-type: application/csv');
header("Content-Disposition: attachment; filename=$fileName");
header("Pragma: no-cache");
header("Expires: 0");
echo stripslashes($this->post->csvData);
die();
}
}

View File

@@ -21,6 +21,7 @@
* @version $Id$
* @link http://www.zentao.cn
*/
$lang->file->common = '附件';
$lang->file->download = '下载附件';
$lang->file->common = '附件';
$lang->file->download = '下载附件';
$lang->file->export2CSV = '导出CSV';
$lang->file->label = '标题:';

View File

@@ -239,6 +239,7 @@ $lang->resource->admin->index = 'index';
/* 其他的一些杂项。*/
$lang->resource->api->getModel = 'getModel';
$lang->resource->file->download = 'download';
$lang->resource->file->export2CSV = 'export2CSV';
$lang->resource->misc->ping = 'ping';
$lang->resource->action->trash = 'trash';
$lang->resource->action->undelete = 'undelete';

View File

@@ -25,6 +25,7 @@
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/treeview.html.php';?>
<?php include '../../common/view/colorize.html.php';?>
<?php include '../../common/view/table2csv.html.php';?>
<script language='Javascript'>
/* 切换浏览方式。*/
function browseByModule()
@@ -56,6 +57,7 @@ function search(active)
<span id='allTab'><?php echo html::a($this->createLink('product', 'browse', "productID=$productID&browseType=all&param=0&orderBy=$orderBy&recTotal=0&recPerPage=200"), $lang->product->allStory);?></span>
</div>
<div class='f-right'>
<?php echo html::export2csv($lang->exportCSV, $lang->setFileName);?>
<?php if(common::hasPriv('story', 'create')) echo html::a($this->createLink('story', 'create', "productID=$productID&moduleID=$moduleID"), $lang->story->create); ?>
</div>
</div>
@@ -66,7 +68,7 @@ function search(active)
<div class="yui-main">
<div class="yui-b">
<table class='table-1 fixed colored tablesorter'>
<table class='table-1 fixed colored tablesorter datatable'>
<thead>
<tr class='colhead'>
<?php $vars = "productID=$productID&browseType=$browseType&param=$moduleID&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
@@ -79,7 +81,7 @@ function search(active)
<th class='w-hour'><?php common::printOrderLink('estimate', $orderBy, $vars, $lang->story->estimateAB);?></th>
<th><?php common::printOrderLink('status', $orderBy, $vars, $lang->statusAB);?></th>
<th><?php common::printOrderLink('stage', $orderBy, $vars, $lang->story->stageAB);?></th>
<th class='w-100px'><?php echo $lang->actions;?></th>
<th class='w-100px {sorter:false}'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>

View File

@@ -412,14 +412,30 @@ class projectModel extends model
public function getBurnData($projectID = 0)
{
$project = $this->getById($projectID);
$sql = $this->dao->select('date AS name, `left` AS value')->from(TABLE_BURN)->where('project')->eq((int)$projectID);
if($project->end == '0000-00-00')
{
$project->end = strtotime('1 month later');
}
a($project->end);
/* 从燃烧图表中查找最近的15条记录。*/
$sets = $this->dao->select('date AS name, `left` AS value')
->from(TABLE_BURN)
->where('project')
->eq((int)$projectID)
->orderBy('date desc')
->limit(15)
->fetchAll('name');
if($sets) $sets = array_reverse($sets);
/* 如果记录数小于30。*/
if(count($sets) < 30)
{
}
/* 没有指定结束日期的情况。*/
if($project->end == '0000-00-00')
{
$sets = $sql->orderBy('date_desc')->limit(14)->fetchAll('name');
$sets = array_reverse($sets);
/* 如果没有记录,手工补齐。*/
if(!$sets)
{
@@ -436,7 +452,6 @@ class projectModel extends model
}
else
{
$sets = $sql->orderBy('date')->fetchAll('name');
$current = $project->begin;
$end = $project->end;
if($sets)
@@ -448,6 +463,7 @@ class projectModel extends model
/* 根据当前日期和项目最后结束的日期,补足后续日期。*/
if(helper::diffDate($end, $current) > 0)
{
$i = 0;
while(true)
{
$nextDay = date(DT_DATE1, strtotime('next day', strtotime($current)));
@@ -455,6 +471,8 @@ class projectModel extends model
$sets[$current]->name = $current;
$sets[$current]->value = ''; // value为空这样fushioncharts不会打印节点。
if($nextDay == $end) break;
if($i == 14) break;
$i ++;
}
}
foreach($sets as $set) $set->name = substr($set->name, 5);

View File

@@ -24,9 +24,10 @@
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/colorize.html.php';?>
<?php include '../../common/view/table2csv.html.php';?>
<?php include './taskheader.html.php';?>
<div class='yui-d0'>
<table class='table-1 fixed colored tablesorter'>
<table class='table-1 fixed colored tablesorter datatable'>
<?php $vars = "projectID=$project->id&status=all&orderBy=%s&recTotal=$recTotal&recPerPage=$recPerPage"; ?>
<thead>
<tr class='colhead'>
@@ -40,7 +41,7 @@
<th class='w-date'> <?php common::printOrderLink('deadline', $orderBy, $vars, $lang->task->deadlineAB);?></th>
<th class='w-status'><?php common::printOrderLink('status', $orderBy, $vars, $lang->statusAB);?></th>
<th><?php common::printOrderLink('story', $orderBy, $vars, $lang->task->story);?></th>
<th class='w-70px'><?php echo $lang->actions;?></th>
<th class='w-70px {sorter:false}'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>

View File

@@ -17,6 +17,7 @@
</div>
<div class='f-right'>
<?php
echo html::export2csv($lang->exportCSV, $lang->setFileName);
common::printLink('project', 'importTask', "project=$project->id", $lang->project->importTask);
common::printLink('task', 'create', "project=$project->id", $lang->task->create);
?>

View File

@@ -25,6 +25,7 @@
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/treeview.html.php';?>
<?php include '../../common/view/colorize.html.php';?>
<?php include '../../common/view/table2csv.html.php';?>
<script language='Javascript'>
/* 切换至按模块浏览。*/
function browseByModule(active)
@@ -58,6 +59,7 @@ function browseBySearch(active)
?>
</div>
<div class='f-right'>
<?php echo html::export2csv($lang->exportCSV, $lang->setFileName);?>
<?php common::printLink('testcase', 'create', "productID=$productID&moduleID=$moduleID", $lang->testcase->create); ?>
</div>
</div>
@@ -68,7 +70,7 @@ function browseBySearch(active)
<div class="yui-main">
<div class='yui-b'>
<?php $vars = "productID=$productID&browseType=$browseType&param=$param&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}"; ?>
<table class='table-1 colored tablesorter'>
<table class='table-1 colored tablesorter datatable'>
<thead>
<tr class='colhead'>
<th class='w-id'> <?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>

235
trunk/www/js/jquery/alert/raw.js vendored Normal file
View File

@@ -0,0 +1,235 @@
// jQuery Alert Dialogs Plugin
//
// Version 1.1
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
// jAlert( message, [title, callback] )
// jConfirm( message, [title, callback] )
// jPrompt( message, [value, title, callback] )
//
// History:
//
// 1.00 - Released (29 December 2008)
//
// 1.01 - Fixed bug where unbinding would destroy all resize events
//
// License:
//
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC.
//
(function($) {
$.alerts = {
// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
verticalOffset: -75, // vertical offset of the dialog from center screen, in pixels
horizontalOffset: 0, // horizontal offset of the dialog from center screen, in pixels/
repositionOnResize: true, // re-centers the dialog on window resize
overlayOpacity: .01, // transparency level of overlay
overlayColor: '#FFF', // base color of overlay
draggable: true, // make the dialogs draggable (requires UI Draggables plugin)
okButton: '&nbsp;OK&nbsp;', // text for the OK button
cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button
dialogClass: null, // if specified, this class will be applied to all dialogs
// Public methods
alert: function(message, title, callback) {
if( title == null ) title = 'Alert';
$.alerts._show(title, message, null, 'alert', function(result) {
if( callback ) callback(result);
});
},
confirm: function(message, title, callback) {
if( title == null ) title = 'Confirm';
$.alerts._show(title, message, null, 'confirm', function(result) {
if( callback ) callback(result);
});
},
prompt: function(message, value, title, callback) {
if( title == null ) title = 'Prompt';
$.alerts._show(title, message, value, 'prompt', function(result) {
if( callback ) callback(result);
});
},
// Private methods
_show: function(title, msg, value, type, callback) {
$.alerts._hide();
$.alerts._overlay('show');
$("BODY").append(
'<div id="popup_container">' +
'<h1 id="popup_title"></h1>' +
'<div id="popup_content">' +
'<div id="popup_message"></div>' +
'</div>' +
'</div>');
if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
// IE6 Fix
var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed';
$("#popup_container").css({
position: pos,
zIndex: 99999,
padding: 0,
margin: 0
});
$("#popup_title").text(title);
$("#popup_content").addClass(type);
$("#popup_message").text(msg);
$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
$("#popup_container").css({
minWidth: $("#popup_container").outerWidth(),
maxWidth: $("#popup_container").outerWidth()
});
$.alerts._reposition();
$.alerts._maintainPosition(true);
switch( type ) {
case 'alert':
$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
$("#popup_ok").click( function() {
$.alerts._hide();
callback(true);
});
$("#popup_ok").focus().keypress( function(e) {
if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
});
break;
case 'confirm':
$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
$("#popup_ok").click( function() {
$.alerts._hide();
if( callback ) callback(true);
});
$("#popup_cancel").click( function() {
$.alerts._hide();
if( callback ) callback(false);
});
$("#popup_ok").focus();
$("#popup_ok, #popup_cancel").keypress( function(e) {
if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
});
break;
case 'prompt':
$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
$("#popup_prompt").width( $("#popup_message").width() );
$("#popup_ok").click( function() {
var val = $("#popup_prompt").val();
$.alerts._hide();
if( callback ) callback( val );
});
$("#popup_cancel").click( function() {
$.alerts._hide();
if( callback ) callback( null );
});
$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
});
if( value ) $("#popup_prompt").val(value);
$("#popup_prompt").focus().select();
break;
}
// Make draggable
if( $.alerts.draggable ) {
try {
$("#popup_container").draggable({ handle: $("#popup_title") });
$("#popup_title").css({ cursor: 'move' });
} catch(e) { /* requires jQuery UI draggables */ }
}
},
_hide: function() {
$("#popup_container").remove();
$.alerts._overlay('hide');
$.alerts._maintainPosition(false);
},
_overlay: function(status) {
switch( status ) {
case 'show':
$.alerts._overlay('hide');
$("BODY").append('<div id="popup_overlay"></div>');
$("#popup_overlay").css({
position: 'absolute',
zIndex: 99998,
top: '0px',
left: '0px',
width: '100%',
height: $(document).height(),
background: $.alerts.overlayColor,
opacity: $.alerts.overlayOpacity
});
break;
case 'hide':
$("#popup_overlay").remove();
break;
}
},
_reposition: function() {
var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
if( top < 0 ) top = 0;
if( left < 0 ) left = 0;
// IE6 fix
if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
$("#popup_container").css({
top: top + 'px',
left: left + 'px'
});
$("#popup_overlay").height( $(document).height() );
},
_maintainPosition: function(status) {
if( $.alerts.repositionOnResize ) {
switch(status) {
case true:
$(window).bind('resize', $.alerts._reposition);
break;
case false:
$(window).unbind('resize', $.alerts._reposition);
break;
}
}
}
}
// Shortuct functions
jAlert = function(message, title, callback) {
$.alerts.alert(message, title, callback);
}
jConfirm = function(message, title, callback) {
$.alerts.confirm(message, title, callback);
};
jPrompt = function(message, value, title, callback) {
$.alerts.prompt(message, value, title, callback);
};
})(jQuery);

102
trunk/www/js/jquery/table2csv/raw.js vendored Normal file
View File

@@ -0,0 +1,102 @@
/**
* see http://www.kunalbabre.com/projects/table2CSV.php;
*/
jQuery.fn.table2CSV = function(options) {
var options = jQuery.extend({
separator: ',',
header: [],
delivery: 'popup', // popup, value
title: 'Please input a file name:'
},
options);
var csvData = [];
var headerArr = [];
var el = this;
//header
var numCols = options.header.length;
var tmpRow = []; // construct header avalible array
var column2Skip = -1; // the column to skip.
if (numCols > 0) {
for (var i = 0; i < numCols; i++) {
tmpRow[tmpRow.length] = formatData(options.header[i]);
}
} else {
var i = 0;
$(el).filter(':visible').find('th').each(function() {
if ($(this).css('display') != 'none' && $(this).attr('class').indexOf("sorter:false") == -1 )
{
tmpRow[tmpRow.length] = formatData($(this).html());
}
if($(this).attr('class').indexOf("sorter:false") > 0)
{
column2Skip = i;
}
i ++;
});
}
row2CSV(tmpRow);
// actual data
$(el).find('tr').each(function() {
var tmpRow = [];
var i = 0;
$(this).filter(':visible').find('td').each(function() {
if(i == column2Skip) return;
if ($(this).css('display') != 'none') tmpRow[tmpRow.length] = formatData($(this).html());
i ++;
});
row2CSV(tmpRow);
});
if (options.delivery == 'popup') {
var mydata = csvData.join('\n');
return popup(mydata);
} else {
var mydata = csvData.join('\n');
return mydata;
}
function row2CSV(tmpRow) {
var tmp = tmpRow.join('') // to remove any blank rows
// alert(tmp);
if (tmpRow.length > 0 && tmp != '') {
var mystr = tmpRow.join(options.separator);
csvData[csvData.length] = mystr;
}
}
function formatData(input) {
// replace " with “
var regexp = new RegExp(/["]/g);
var output = input.replace(regexp, "“");
//HTML
var regexp = new RegExp(/\<[^\<]+\>/g);
var output = output.replace(regexp, "");
// space
var regexp = new RegExp(/[ ]/g);
var output = output.replace(regexp, "");
// break
var regexp = new RegExp(/[\r\n]/g);
var output = output.replace(regexp, "");
if (output == "") return '';
return '"' + output + '"';
}
function popup(data) {
jPrompt(options.title, '', '', function(r)
{
if(!r) return;
fileName = r;
agent = $.browser.msie ? 'ie' : 'notie';
exportLink = createLink('file', 'export2csv', 'agent=' + agent);
$("#exporter").html('<form id="exportform" action="' + exportLink + '" method="post" target="hiddenwin"><input type="hidden" name="fileName" value="' + fileName + '" /><input type="hidden" id="csvData" name="csvData" /></form>');
$("#csvData").val(data);
$("#exportform").submit().remove();
$("#exporter").html('');
return true;
});
}
};

View File

@@ -0,0 +1,57 @@
#popup_container {
font-family: Arial, sans-serif;
font-size: 12px;
min-width: 300px; /* Dialog will be no smaller than this */
max-width: 600px; /* Dialog will wrap after this width */
background: #FFF;
border: solid 5px #999;
color: #000;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
#popup_title {
font-size: 14px;
font-weight: bold;
text-align: center;
line-height: 1.75em;
color: #666;
background: #CCC url(images/alert/title.gif) top repeat-x;
border: solid 1px #FFF;
border-bottom: solid 1px #999;
cursor: default;
padding: 0em;
margin: 0em;
}
#popup_content {
background: 16px 16px no-repeat url(images/alert/info.gif);
padding: 1em 1.75em;
margin: 0em;
}
#popup_content.alert {
background-image: url(images/alert/info.gif);
}
#popup_content.confirm {
background-image: url(images/alert/important.gif);
}
#popup_content.prompt {
background-image: url(images/alert/help.gif);
}
#popup_message {
padding-left: 48px;
}
#popup_panel {
text-align: center;
margin: 1em 0em 0em 1em;
}
#popup_prompt {
margin: .5em 0em;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

View File

@@ -2,4 +2,4 @@ html{overflow:hidden;}
body{height:100%; overflow:auto}
div#footer, div#debugbar, div#hiddenbar{position:absolute;}
.yui-d0 {width: 95%;} /* fix the error of fixed layout table. */
.button-s{padding:0; font-size:14px}
.button-s, .button-c, .button-r{padding:0; font-size:14px}