dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20382
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9275: local vn - Auto generate form (WIP)
------------------------------------------------------------
revno: 9275
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-12-12 12:14:59 +0700
message:
local vn - Auto generate form (WIP)
added:
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm
modified:
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/UploadExcelFileAction.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/generateReportForm.vm
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/import.js
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/menu.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/UploadExcelFileAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/UploadExcelFileAction.java 2011-08-04 08:39:55 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/UploadExcelFileAction.java 2012-12-12 05:14:59 +0000
@@ -71,6 +71,8 @@
private boolean isDraft;
+ private boolean allowNewName = true;
+
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -101,6 +103,11 @@
this.isDraft = isDraft;
}
+ public void setAllowNewName( boolean allowNewName )
+ {
+ this.allowNewName = allowNewName;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -114,9 +121,18 @@
if ( isDraft )
{
- directory = reportLocationManager.getExportReportTemporaryDirectory();
-
- output = new File( directory, (Math.random() * 1000) + fileName );
+ if ( allowNewName )
+ {
+ directory = reportLocationManager.getExportReportTemporaryDirectory();
+
+ output = new File( directory, (Math.random() * 1000) + fileName );
+ }
+ else
+ {
+ directory = reportLocationManager.getExportReportTemporaryDirectory();
+
+ output = new File( directory, fileName );
+ }
}
else
{
@@ -149,5 +165,4 @@
return SUCCESS;
}
-
}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-12 04:43:25 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-12 05:14:59 +0000
@@ -27,35 +27,53 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.apache.commons.io.FilenameUtils.getBaseName;
import static org.apache.commons.io.FilenameUtils.getExtension;
+import static org.apache.commons.io.FilenameUtils.getName;
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
+import static org.hisp.dhis.dataelement.DataElement.DOMAIN_TYPE_AGGREGATE;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
+import static org.hisp.dhis.reportsheet.ExportItem.PERIODTYPE.SELECTED_MONTH;
+import static org.hisp.dhis.reportsheet.ExportItem.TYPE.DATAELEMENT;
+import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
+import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI;
-import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.reportsheet.ExportItem;
import org.hisp.dhis.reportsheet.ExportReport;
import org.hisp.dhis.reportsheet.ExportReportNormal;
import org.hisp.dhis.reportsheet.ExportReportService;
+import org.hisp.dhis.reportsheet.state.SelectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.Action;
@@ -69,8 +87,39 @@
* @version $Id$
*/
-public class AutoGenerateFormByTemplate implements Action
+public class AutoGenerateFormByTemplate
+ implements Action
{
+ private static final String REPORT_EXCEL_GROUP = "BAO CAO THONG KE";
+
+ private static final String WORKBOOK_OPENTAG = "<workbook>";
+
+ private static final String WORKBOOK_CLOSETAG = "</workbook>";
+
+ private static final String MERGEDCELL_OPENTAG = "<MergedCells>";
+
+ private static final String MERGEDCELL_CLOSETAG = "</MergedCells>";
+
+ private String excelFileName = "";
+
+ private String commonName = "";
+
+ /**
+ * The workbook we are reading from a given file
+ */
+ private Workbook WORKBOOK;
+
+ private FormulaEvaluator evaluatorFormula;
+
+ /**
+ * The encoding to write
+ */
+ private StringBuffer xml = new StringBuffer( 200000 );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
@Autowired
private DataElementService dataElementService;
@@ -78,7 +127,7 @@
private DataElementCategoryService categoryService;
@Autowired
- private DataEntryFormService dataEntryFormService;
+ private DataEntryFormService dataEntryFormService;
@Autowired
private DataSetService dataSetService;
@@ -86,10 +135,23 @@
@Autowired
private ExportReportService exportReportService;
- /**
- * The workbook we are reading from a given file
- */
- private Workbook WORKBOOK;
+ @Autowired
+ protected SelectionManager selectionManager;
+
+ // -------------------------------------------------------------------------
+ // Input && Output
+ // -------------------------------------------------------------------------
+
+ private String xmlStructureResponse;
+
+ public String getXmlStructureResponse()
+ {
+ return xmlStructureResponse;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
public String execute()
{
@@ -98,7 +160,10 @@
try
{
- autoGenerateFormByTemplate( "d:\\template_file.xls", collectSheets );
+ autoGenerateFormByTemplate( selectionManager.getUploadFilePath(), collectSheets );
+
+ xmlStructureResponse = xml.toString();
+ xml = null;
}
catch ( Exception e )
{
@@ -107,12 +172,12 @@
return SUCCESS;
}
-
- // -------------------------------------------------------------------------
- // Get & Set methods
- // -------------------------------------------------------------------------
-
- private void cleanUpForResponse()
+
+ // -------------------------------------------------------------------------
+ // Sub-methods
+ // -------------------------------------------------------------------------
+
+ private void cleanUp()
{
System.gc();
}
@@ -128,15 +193,14 @@
* @exception java.io.IOException
*/
- private String excelFileName = "";
-
private void autoGenerateFormByTemplate( String pathFileName, Set<Integer> collectSheets )
throws Exception
{
- this.cleanUpForResponse();
+ this.cleanUp();
InputStream inputSteam = new FileInputStream( pathFileName );
- excelFileName = new File( pathFileName ).getName();
+ excelFileName = getName( pathFileName );
+ commonName = getBaseName( pathFileName );
if ( getExtension( pathFileName ).equals( "xls" ) )
{
@@ -160,100 +224,129 @@
private void writeFormattedXML( Collection<Integer> collectSheets )
throws Exception
- {
- for ( Integer sheet : collectSheets )
- {
- createFormByComment( sheet );
- }
+ {
+ this.writeXMLMergedDescription( collectSheets );
+
+ xml.append( WORKBOOK_OPENTAG );
+
+ createFormByComment( 1, categoryService.getDefaultDataElementCategoryOptionCombo() );
+
+ xml.append( WORKBOOK_CLOSETAG );
}
- // -------------------------------------------------------------------------
- // Sub-methods
- // -------------------------------------------------------------------------
-
- private void createFormByComment( int sheetNo )
+ private void createFormByComment( int sheetNo, DataElementCategoryOptionCombo optionCombo )
{
- DataElementCategoryCombo catagoryCombo = categoryService.getDefaultDataElementCategoryOptionCombo()
- .getCategoryCombo();
- int catagoryOptionComboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
- PeriodType periodType = PeriodType.getPeriodTypeByName( "Monthly" );
- StringBuffer htmlCode = new StringBuffer();
+ PeriodType periodType = PeriodType.getPeriodTypeByName( MonthlyPeriodType.NAME );
+
+ // Create new DataSet
+ DataSet dataSet = new DataSet( commonName, commonName, periodType );
+
+ // Create new ExportReport
+ ExportReport exportReport = new ExportReportNormal( commonName, REPORT_EXCEL_GROUP, excelFileName, null );
+ exportReportService.addExportReport( exportReport );
+
Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 );
- DataSet dataSet = new DataSet( excelFileName, excelFileName, periodType );
-
- // Generate report
- ExportReport exportReport = new ExportReportNormal();
- exportReport.setName( WORKBOOK.getSheetName( sheetNo - 1 ) );
- exportReport.setExcelTemplateFile( excelFileName );
- exportReport.setGroup( excelFileName );
- exportReport.setCreatedBy( "DHIS-System" );
- int reportId = exportReportService.addExportReport( exportReport );
+ xml.append( "<sheet id='" + (sheetNo) + "'>" );
+ xml.append( "<name><![CDATA[" + s.getSheetName() + "]]></name>" );
try
{
for ( Row row : s )
{
+ xml.append( "<row index='" + row.getRowNum() + "'>" );
+
+ Map<Integer, Integer> idxMap = new HashMap<Integer, Integer>();
+
for ( Cell cell : row )
{
Comment cmt = cell.getCellComment();
- if ( cell.getCellComment() != null )
+
+ if ( cmt != null )
{
String deName = cell.getStringCellValue();
- String[] indexes = cmt.getString().toString().split( "," );
+ String[] indexes = cmt.getString().getString().split( "," );
+
int rowIndex = cell.getRowIndex();
for ( String index : indexes )
{
- String name = deName + "(" + index + ")";
- int idx = Integer.parseInt( index ) - 1;
-
- // Generate dataElement
+ String name = deName + " (" + index + ")";
+ int idx = Integer.parseInt( index );
+
+ // Generate DataElement
DataElement dataElement = new DataElement( name );
- dataElement.setShortName( name );
+ /** TAKE CARE OF SHORT_NAME IS TOO LONG */
+ dataElement.setShortName( System.currentTimeMillis() + "" );
dataElement.setActive( true );
- dataElement.setDomainType( "aggregate" );
- dataElement.setType( DataElement.VALUE_TYPE_INT );
- dataElement.setNumberType( DataElement.VALUE_TYPE_INT );
- dataElement.setCategoryCombo( catagoryCombo );
- dataElement.setAggregationOperator( "sum" );
dataElement.setZeroIsSignificant( false );
+ dataElement.setDomainType( DOMAIN_TYPE_AGGREGATE );
+ dataElement.setType( VALUE_TYPE_INT );
+ dataElement.setNumberType( VALUE_TYPE_INT );
+ dataElement.setAggregationOperator( AGGREGATION_OPERATOR_SUM );
+ dataElement.setCategoryCombo( optionCombo.getCategoryCombo() );
+
int deId = dataElementService.addDataElement( dataElement );
- // Add the dataelement into the dataset
+ idxMap.put( idx - 1, deId );
+
+ // Add the dataElement into the dataSet
dataSet.addDataElement( dataElement );
- // Put text field into the cell(rowIndex,idx)
- // htmlCode.append( str );
-
- // Generate report item
+ // Generate Report Item
ExportItem exportItem = new ExportItem();
exportItem.setName( name );
- exportItem.setItemType( "dataelement" );
- exportItem.setRow( rowIndex );
+ exportItem.setItemType( DATAELEMENT );
+ exportItem.setRow( rowIndex + 1 );
exportItem.setColumn( idx );
- exportItem.setExpression( "[" + deId + "." + catagoryOptionComboId + "]" );
- exportItem.setPeriodType( "selected_month" );
- exportItem.setSheetNo( (sheetNo) );
- exportItem.setExportReport( exportReportService.getExportReport( reportId ) );
+ exportItem.setExpression( "[" + deId + "." + optionCombo.getId() + "]" );
+ exportItem.setPeriodType( SELECTED_MONTH );
+ exportItem.setSheetNo( sheetNo );
+ exportItem.setExportReport( exportReport );
+
exportReportService.addExportItem( exportItem );
-
}
}
+
+ xml.append( "<col no='" + cell.getColumnIndex() + "'>" );
+
+ if ( idxMap.containsKey( cell.getColumnIndex() ) )
+ {
+ xml.append( "<data><![CDATA[" + "<input id=\"" + idxMap.get( cell.getColumnIndex() ) + "-"
+ + optionCombo.getId()
+ + "-val\" style=\"width:7em;text-align:right\" title=\"\" value=\"\">" + "]]></data>" );
+ }
+ else if ( (cell.getCellStyle() != null || cell.getCellType() != Cell.CELL_TYPE_BLANK)
+ && !s.isColumnHidden( cell.getColumnIndex() ) )
+ {
+ xml.append( "<data><![CDATA["
+ + readValueByPOI( row.getRowNum() + 1, cell.getColumnIndex() + 1, s, evaluatorFormula )
+ + "]]></data>" );
+
+ this.readingDetailsFormattedCell( s, cell );
+
+ }
+ xml.append( "</col>" );
}
+ xml.append( "</row>" );
}
-
- DataEntryForm dataEntryForm = new DataEntryForm( "DataEntry form", htmlCode.toString() );
+ xml.append( "</sheet>" );
+
+ // Update DataSet
+ DataEntryForm dataEntryForm = new DataEntryForm( commonName );
dataEntryFormService.addDataEntryForm( dataEntryForm );
dataSet.setDataEntryForm( dataEntryForm );
- dataSetService.addDataSet( dataSet );
+ int dataSetId = dataSetService.addDataSet( dataSet );
+ // Update ExportReport
Set<DataSet> dataSets = new HashSet<DataSet>();
dataSets.add( dataSet );
-
+
exportReport.setDataSets( dataSets );
exportReportService.updateExportReport( exportReport );
+
+ xml.append( "<ds id='" + dataSetId + "' n='" + commonName + "'/>" );
}
catch ( Exception e )
@@ -262,4 +355,92 @@
System.err.println( "Error: " + e.getMessage() );
}
}
+
+ // -------------------------------------------------------------------------
+ // Get the merged cell's information
+ // -------------------------------------------------------------------------
+
+ private void readingDetailsFormattedCell( Sheet sheet, Cell objCell )
+ {
+ // The format information
+ CellStyle format = objCell.getCellStyle();
+
+ if ( format != null )
+ {
+ xml.append( "<format a='" + convertAlignmentString( format.getAlignment() ) + "'" );
+ xml.append( " b='"
+ + (format.getBorderBottom() + format.getBorderLeft() + format.getBorderRight() + format.getBorderTop())
+ + "'" );
+
+ Font font = WORKBOOK.getFontAt( format.getFontIndex() );
+
+ if ( font != null )
+ {
+ xml.append( "><font s='" + font.getFontHeightInPoints() + "'" );
+ xml.append( " b='" + (font.getBoldweight() == Font.BOLDWEIGHT_BOLD ? "1" : "0") + "'" );
+ xml.append( " i='" + font.getItalic() + "'" );
+ xml.append( " c='" + getSimilarColor( font.getColor() ) + "'" );
+ xml.append( "/>" );
+
+ xml.append( "</format>" );
+ }
+ else
+ {
+ xml.append( "/>" );
+ }
+ }
+ }
+
+ private void writeXMLMergedDescription( Collection<Integer> collectSheets )
+ throws IOException
+ {
+ // Open the main Tag //
+ xml.append( MERGEDCELL_OPENTAG );
+
+ for ( Integer sheet : collectSheets )
+ {
+ writeMergedInfoBySheetNo( sheet );
+ }
+
+ // Close the main Tag //
+ xml.append( MERGEDCELL_CLOSETAG );
+ }
+
+ private void writeMergedInfoBySheetNo( int sheetNo )
+ {
+ Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
+ CellRangeAddress cellRangeAddress = null;
+
+ for ( int i = 0; i < sheet.getNumMergedRegions(); i++ )
+ {
+ cellRangeAddress = sheet.getMergedRegion( i );
+
+ if ( cellRangeAddress.getFirstColumn() != cellRangeAddress.getLastColumn() )
+ {
+ xml.append( "<cell " + "iKey='" + (sheetNo) + "#" + cellRangeAddress.getFirstRow() + "#"
+ + cellRangeAddress.getFirstColumn() + "'>"
+ + (cellRangeAddress.getLastColumn() - cellRangeAddress.getFirstColumn() + 1) + "</cell>" );
+ }
+ }
+ }
+
+ private String getSimilarColor( short index )
+ {
+ if ( IndexedColors.BLUE.getIndex() == index )
+ {
+ return "blue";
+ }
+
+ if ( IndexedColors.DARK_BLUE.getIndex() == index )
+ {
+ return "darkblue";
+ }
+
+ if ( IndexedColors.BROWN.getIndex() == index )
+ {
+ return "brown";
+ }
+
+ return "";
+ }
}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-11 15:34:39 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-12 05:14:59 +0000
@@ -1849,6 +1849,20 @@
<param name="onExceptionReturn">plainTextError</param>
</action>
+ <action name="showAutoGenerateForm"
+ class="org.hisp.dhis.reportsheet.action.NoAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm</param>
+ <param name="menu">/dhis-web-spreadsheet-reporting/menu.vm</param>
+ <param name="requiredAuthorities">F_AUTO_GENERATE_FORM_BY_TEMPLATE</param>
+ </action>
+
+ <action name="uploadExcelTemplateForGenerateForm"
+ class="org.hisp.dhis.reportsheet.filemanager.action.UploadExcelFileAction">
+ <result name="success" type="redirect">showAutoGenerateForm.action</result>
+ <interceptor-ref name="fileUploadStack" />
+ </action>
+
<action name="autoGenerateFormByTemplate"
class="org.hisp.dhis.reportsheet.preview.action.AutoGenerateFormByTemplate">
<result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/generateReportForm.vm'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/generateReportForm.vm 2012-11-13 07:04:37 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/generateReportForm.vm 2012-12-12 05:14:59 +0000
@@ -1,3 +1,6 @@
+<meta http-equiv="Cache-control" content="private;no-cache">
+<meta http-equiv="pragma" content="no-cache">
+
<script type="text/javascript">
jQuery(document).ready(function()
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-12 05:14:59 +0000
@@ -0,0 +1,174 @@
+/**
+ * Global variables
+ */
+
+spreadsheetTreePath = '../dhis-web-spreadsheet-reporting/';
+
+idTemp = null;
+importlist = null;
+importItemIds = new Array();
+
+// ----------------------------------------------------------------------
+// Methods
+// ----------------------------------------------------------------------
+
+function validateUploadExcelTemplateForGenerateForm()
+{
+ jQuery( "#upload" ).upload( 'validateUploadExcelTemplate.action', { 'draft': true },
+ function ( data )
+ {
+ data = data.getElementsByTagName('message')[0];
+ var type = data.getAttribute("type");
+ alert(type);
+ if ( type == 'error' ) {
+ setMessage( data.firstChild.nodeValue );
+ } else {
+ uploadExcelTemplateForGenerateForm();
+ }
+ }, 'xml'
+ );
+}
+
+function uploadExcelTemplateForGenerateForm()
+{
+ jQuery( "#upload" ).upload( 'uploadExcelTemplateForGenerateForm.action',
+ { 'draft': true, 'allowNewName': false },
+ function( data, e ) {
+ try {
+ window.location.reload();
+ }
+ catch(e) {
+ alert(e);
+ }
+ }
+ );
+}
+
+function autoGenerateFormByTemplate()
+{
+ $.ajax({
+ cache: false,
+ url: spreadsheetTreePath + "autoGenerateFormByTemplate.action",
+ dataType: 'xml',
+ success: autoGenerateFormByTemplateReceived
+ });
+}
+
+function autoGenerateFormByTemplateReceived( parentElement )
+{
+ var aKey = new Array();
+ var aMerged = new Array();
+ var cells = parentElement.getElementsByTagName( 'cell' );
+
+ for (var i = 0 ; i < cells.length ; i ++)
+ {
+ aKey[i] = cells[i].getAttribute( 'iKey' );
+ aMerged[i] = cells[i].firstChild.nodeValue;
+ }
+
+ var _index = 0;
+ var _orderSheet = 0;
+ var _sPattern = "";
+ var _rows = "";
+ var _cols = "";
+ var _sHTML = [];
+ var _sheets = parentElement.getElementsByTagName( 'sheet' );
+
+ var dataSetId = getElementAttribute( parentElement, 'ds', 'id' );
+ var dataSetName = getElementAttribute( parentElement, 'ds', 'n' );
+
+ for (var s = 0 ; s < _sheets.length ; s ++)
+ {
+ _rows = _sheets[s].getElementsByTagName( 'row' );
+ _orderSheet = getRootElementAttribute( _sheets[s], "id" );
+
+ _sHTML.push( "<table>" );
+
+ for (var i = 0 ; i < _rows.length ; i ++)
+ {
+ _index = 0;
+ _sHTML.push( "<tr>" );
+
+ _cols = _rows[i].getElementsByTagName( 'col' );
+
+ for (var j = 0 ; j < _cols.length ; )
+ {
+ var _number = getRootElementAttribute( _cols[j], 'no' );
+ var keyId = getRootElementAttribute( _cols[j], 'id' );
+
+ // Printing out the unformatted cells
+ for (; _index < _number ; _index ++)
+ {
+ _sHTML.push( "<td/>" );
+ }
+
+ if ( _index == _number )
+ {
+ var _sData = getElementValue( _cols[j], 'data' );
+ var _align = getElementAttribute( _cols[j], 'format', 'a' );
+ var _border = getElementAttribute( _cols[j], 'format', 'b' );
+ var _size = getElementAttribute( _cols[j], 'font', 's' );
+ var _bold = getElementAttribute( _cols[j], 'font', 'b' );
+ var _italic = getElementAttribute( _cols[j], 'font', 'i' );
+ var _color = getElementAttribute( _cols[j], 'font', 'c' );
+
+ // If this cell is merged - Key's form: Sheet#Row#Col
+ _sPattern = _orderSheet + "#" + i + "#" + _number;
+ var _colspan = getMergedNumberForEachCell( aKey, _sPattern, aMerged );
+
+ // Jumping for <For Loop> AND <Empty Cells>
+ j = Number(j) + Number(_colspan);
+ _index = Number(_index) + Number(_colspan);
+ _size = Number(_size) + 2;
+
+ _sHTML.push( "<td align='", _align, "' colspan='", _colspan, "'" );
+ _sHTML.push( " style='font-size:", _size, "px" );
+ _sHTML.push( _color == "" ? "'" : ";color:" + _color + "'" );
+ _sHTML.push( _border > 0 ? " ui-widget-content" : "" );
+
+ if ( _bold == "1" )
+ {
+ _sData = "<b>" + _sData + "</b>";
+ }
+ if ( _italic == "true" )
+ {
+ _sData = "<i>" + _sData + "</i>";
+ }
+
+ _sHTML.push( "'>", _sData, "</td>" );
+ }
+ }
+ _sHTML.push( "</tr>" );
+ }
+ _sHTML.push( "</table>" );
+ }
+
+ jQuery( '#previewDiv' ).html( _sHTML.join('') );
+ showById( "previewDiv" );
+
+ unLockScreen();
+ showSuccessMessage( "auto_generate_form_completed" );
+
+ if ( _sHTML.length > 0 )
+ {
+ jQuery.postUTF8( '../dhis-web-maintenance-dataset/saveDataEntryForm.action',
+ {
+ dataSetIdField: dataSetId,
+ nameField: dataSetName,
+ style: 'regular',
+ designTextarea: _sHTML.join('')
+ } );
+ }
+}
+
+function getMergedNumberForEachCell( aKey, sKey, aMerged )
+{
+ for (var i = 0 ; i < aKey.length ; i ++)
+ {
+ if ( aKey[i] == sKey )
+ {
+ return Number(aMerged[i]);
+ }
+ }
+ return 1;
+}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/import.js'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/import.js 2012-11-27 07:32:34 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/import.js 2012-12-12 05:14:59 +0000
@@ -168,8 +168,8 @@
function rollbackImporting()
{
jQuery.get( "rollbackImporting.action", {}, function( json ) {
- if ( json.response && json.response == "success" ) {
- showSuccessMessage( json.message );
+ if ( json.response && json.response == "success" && json.message != "" ) {
+ showSuccessMessage( json.message, 3500 );
} else {
showWarningMessage( i18n_no_value_rollbacked );
}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/menu.vm'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/menu.vm 2012-11-27 06:33:42 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/menu.vm 2012-12-12 05:14:59 +0000
@@ -20,6 +20,11 @@
<li><a href="getImportingParams.action">$i18n.getString( "import" ) </a></li>
</ul>
+<h2><a href="showAutoGenerateForm.action">$i18n.getString( "auto_generate_form_by_template" ) </a></h2>
+<ul>
+ <li><a href="showAutoGenerateForm.action">$i18n.getString( "auto_generate_form_by_template" ) </a></li>
+</ul>
+
<script type="text/javascript">
var i18n_deleted_file = '$encoder.jsEncode( $i18n.getString( "deleted_file" ) )';
var i18n_name = '$encoder.jsEncode( $i18n.getString( "name" ) )';
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm 2012-12-12 05:14:59 +0000
@@ -0,0 +1,27 @@
+<script type="text/javascript" src="javascript/autoGenerateForm.js"></script>
+<body>
+
+#if( $!fileExcel )
+ <div id="messageUpload">
+ $i18n.getString( "upload_file" ) $i18n.getString( "success" )<br>$fileExcel.getName()
+ </div>
+#end
+<span id="message" style="top:70px;right:5px;position:fixed;width:200px;z-index:100009" onclick="hideById(this.id);"></span>
+
+<table width="82%">
+ <h3>$i18n.getString( 'auto_generate_form_by_template' ) #openHelp( "" )</h3>
+ <form name="uploadForm" id="uploadForm" action="autoGenerateFormByTemplate.action" method="POST" enctype="multipart/form-data">
+ <tr>
+ <td width="18%" style=" width:25% ">$i18n.getString( 'select_excel_file' )</td>
+ <td width="82%">
+ <input type="file" id="upload" name="upload" onChange="enable( 'uploadButton' );">
+ <input name="uploadButton" id="uploadButton" type="button" value="$i18n.getString( 'upload_file' )" onclick="validateUploadExcelTemplateForGenerateForm();"/>
+ <input type="button" onClick="javascript: autoGenerateFormByTemplate();" style="width:150px" value="$i18n.getString( 'auto_generate_form' )" />
+ </td>
+ </tr>
+ </form>
+</table>
+
+<div id="previewDiv"></div>
+
+</body>
\ No newline at end of file