<!-- /focus/gexportstorydialog.vm -->
#set ($SAVE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.save")))
#set ($CANCEL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.cancel")))
#set ($BLANK_ENTRY_ERROR = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.blankentryerror")))
#set ($EXPORTSTORY_DLG_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.exportstorydlgtitle")))
#set ($LOAD_ERROR = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.loaderror")))
#set ($ERROR_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.errortitle")))
#set ($EXPORTSTORY_WAIT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.exportstorywait")))
#set ($INVALID_ENTRIES = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.invalidentries")))
#set ($MAIN_TEXT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.maintext")))
#set ($BAFO_TEXT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.bafotext","R")))
#set ($XML_TEXT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.xmltext")))
#set ($MORE_INFO= $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.moreinfo")))
#set ($ENTIOSYSMSG= $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.enthiosysmsg")))
#set ($ENTIOSYS_TITLE= $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "gexportstorydialog", "gexportstorydialog.title")))

// ---------- exportStory Dialog  ---------

var EXPORTSTORYLabels = {
    SAVE: '$SAVE',
    CANCEL: '$CANCEL',
    BLANK_ENTRY_ERROR: '$BLANK_ENTRY_ERROR',
    EXPORTSTORY_DLG_TITLE: '$EXPORTSTORY_DLG_TITLE',
    LOAD_ERROR: '$LOAD_ERROR',
    ERROR_TITLE: '$ERROR_TITLE',
    EXPORTSTORY_WAIT: '$EXPORTSTORY_WAIT',
    INVALID_ENTRIES: '$INVALID_ENTRIES',
	MORE_INFO:'$MORE_INFO',
	MAIN_TEXT:'$MAIN_TEXT',
	XML_TEXT:'$XML_TEXT',
	BAFO_TEXT: '$BAFO_TEXT'	,
	SELECTED_LINK_COLOR:'#000000',
	UNSELECTED_LINK_COLOR:'#808080',
	BAFO_DLG_TITLE: '$ENTIOSYS_TITLE'
};

var exportStoryDialog = {
	    ///////////////////////////////////////////////
	   // Data Members
	   ///////////////////////////////////////////////

		selectedProjectId: null,
		selectedBacklogId:null,
		saveSuccessHandlerFn:null,
		exportStoryDS:null,
		dlgFormRec:null,
		bafoRadio: null,
		xmlRadio:null,
			
	    ///////////////////////////////////////////////
	   // constructor
	   ///////////////////////////////////////////////

		init : function() {
				///////////////////////////////////////////
   				// form record
				///////////////////////////////////////////
                exportStoryDialog.dlgFormRec = Ext.data.Record.create( [
                        { name:'projectid' },
                        { name:'backlogid' },
						{ name:'noofstories' }
                    ]);
	           ///////////////////////////////////////////////
			   // Create UI objects
			   ///////////////////////////////////////////////
		
			   var xmlMsg = "<span style='text-align:top;' id='xmlMsg_Span'><br>$XML_TEXT</span>";
				var bafoMsg = "<span style='text-align:top;' id='bafoMsg_Span'>$BAFO_TEXT<br></span>";
				var url = 'http://buyafeature.com';
				bafoMsg += "<div style='text-align:right;width:100%' class='tbName' onmouseover='className=\"tbHover\"' onmouseout='className=\"tbName\"' onclick='javascript:exportStoryDialog.showUrl()'><b>$MORE_INFO</b></div>";	
				
				exportStoryDialog.xmlRadio = new Ext.ImageButton( {								 
									text: '',
									imgPath: '../themes/default/images/xmlicon_r.png', 																	
									pressedImgPath:'../themes/default/images/xmlicon_p.png',
			    					tooltip: 'XML', 
									enableToggle: true,
									pressed: true,
									allowDepress :true,
									toggleGroup: 'exportToggleGroup',									
									imgWidth : 92,
									imgHeight : 88,
									imgId:'xmlRadio',
									handler : function(btn){
										exportStoryDialog.xmlRadio.onPressed('xmlRadio');
										exportStoryDialog.bafoRadio.onUnPressed('bafoRadio');
										document.getElementById('xmlMsg_Span').style.color= EXPORTSTORYLabels.SELECTED_LINK_COLOR;
										document.getElementById('bafoMsg_Span').style.color=EXPORTSTORYLabels.UNSELECTED_LINK_COLOR;
							
									}				
								}); 
				exportStoryDialog.bafoRadio = new Ext.ImageButton( {								  									
									text: '',
									imgPath: '../themes/default/images/enthiosys_r.png', 																								
									pressedImgPath:'../themes/default/images/enthiosys_p.png',
									tooltip: 'BaFO', 
									enableToggle: true,
									pressed: false,
									allowDepress :true,				    				
									toggleGroup: 'exportToggleGroup',
									imgWidth : 92,
									imgHeight : 88,	
									imgId:'bafoRadio',
									handler : function(btn){
											exportStoryDialog.bafoRadio.onPressed('bafoRadio');
											exportStoryDialog.xmlRadio.onUnPressed('xmlRadio');
											document.getElementById('bafoMsg_Span').style.color= EXPORTSTORYLabels.SELECTED_LINK_COLOR;
											document.getElementById('xmlMsg_Span').style.color=EXPORTSTORYLabels.UNSELECTED_LINK_COLOR;
							

										}});
				
			   ///////////////////////////////////////////////
			   // Create Form
			   ///////////////////////////////////////////////

				var exportstoryMsg = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>$MAIN_TEXT</span>";
				

                // form control
                exportStoryDialog.dlgFormCtrl = new Ext.FormPanel({
            		buttonAlign: 'right',
                	labelAlign: 'right',
                    labelWidth: 70,
                    frame:true,
                    width: 446,
                    reader: new Ext.data.JsonReader({}, exportStoryDialog.dlgFormRec),
					items: [
                       
							{
									id:'exportstory-general-msg',							        
									height:18,
							        html:exportstoryMsg									
							},
							{
	                            layout: 'column',
    	                        height: 90,
        	                    items: [
		                                {
		                                    columnWidth:.25,                                    
		                                    items: [  exportStoryDialog.xmlRadio ]                                       
		                                },
		                                {
		                                    columnWidth:.75,
		                                    items: [ {
											id:'exportstory-xml-msg',				      
									        html:xmlMsg
											} ]
		                                }
								]      
                        	},	
							{
	                            layout: 'column',
    	                        height: 115,
        	                    items: [
		                                {
		                                    columnWidth:.25,                                    
		                                    items: [  exportStoryDialog.bafoRadio ]                                       
		                                },
		                                {
		                                    columnWidth:.75,
		                                    items: [ {
											id:'exportstory-bafo-msg',				      
									        html:bafoMsg
											} ]
		                                }
								]      
                        	}											
					],
                buttons: [
				{
				            id: 'exportStoryDlgExportButton',
                            text: EXPORTSTORYLabels.SAVE,
                            handler: function(){
								if(exportStoryDialog.bafoRadio.pressed)						
								{
									exportStoryDialog.dialog.hide();
									exportStoryDialog.showEnthiosysDlg();
								}
								else	
			        			{
									exportStoryDialog.exportStories();
									
								}	
							}
                        },
                        {
						    id: 'exportStoryDlgCancelButton',
                            text: EXPORTSTORYLabels.CANCEL,
                            handler: function() {
                                  exportStoryDialog.hideAll();
                            }
                        }]
                });       
				
			     ///////////////////////////////////////////////////////////////
				 // enthiosys form control
			  	var enthiosysmsg = "$ENTIOSYSMSG";


                exportStoryDialog.bafodlgFormCtrl = new Ext.FormPanel({
            		buttonAlign: 'right',
                	labelAlign: 'right',
                    labelWidth: 70,
                    frame:true,
                    width: 446,                   
					items: [
                       
							{
									id:'exportstory-entiosys-msg',							        
									height:300,
							       html:enthiosysmsg									
							}
					],
                buttons: [{
				            id: 'exportStoryDlgExportButtonE',
                            text: EXPORTSTORYLabels.SAVE,
                            handler: function(){	
																					
			        			exportStoryDialog.exportStories();
							}
                        },
                        {
						    id: 'exportStoryDlgCancelButtonE',
                            text: EXPORTSTORYLabels.CANCEL,
                            handler: function() {
                                      exportStoryDialog.hideAll();
                            }
                        }]
                }); 
							     
			 
        },
		showUrl : function() {
				window.open("http://buyafeature.com","buyafeature");
			},
		hideAll:function()
		{
			exportStoryDialog.dialog.hide();
		  if (exportStoryDialog.bafodialog) {
		  	exportStoryDialog.bafodialog.hide();
		  }	  
		},
		
         
        //////////////////////////////////////////////////    
        // ---------- Private methods ----------
        //////////////////////////////////////////////////  
		createDialog:function()
		{
			  // form dialog
                if(!exportStoryDialog.dialog){
                    exportStoryDialog.dialog = new Ext.Window({
                        layout:'fit',
                        width:446,
                        height:325,
                        closeAction:'hide',
                        plain: true,
                        items: exportStoryDialog.dlgFormCtrl,
                        modal: true,
                        resizable : false,
                        closable: true,
                        renderTo: document.body
                    });
                };
				
                exportStoryDialog.dialog.on('show', function(){
                    
                }, null, {delay: 100});
  
		},
		showEnthiosysDlg:function()
		{
			if(!exportStoryDialog.bafodialog){					
                    exportStoryDialog.bafodialog = new Ext.Window({
                        layout:'fit',
                        width:446,
                        height:350,
                        closeAction:'hide',
                        plain: true,
                        items: exportStoryDialog.bafodlgFormCtrl,
                        modal: true,
                        resizable : false,
                        closable: true,
                        renderTo: document.body
                    });
                };
							exportStoryDialog.bafodialog.setTitle(EXPORTSTORYLabels.EXPORTSTORY_DLG_TITLE + ": " + EXPORTSTORYLabels.BAFO_DLG_TITLE);            
				exportStoryDialog.bafodialog.show();
			},

        
		exportStories : function() {          
				exportStoryDialog.hideAll();			
				
				var xmlMethodSignature = document.getElementById("xmlMethodSignature");
	            xmlMethodSignature.value = "<?xml version = '1.0' encoding = 'UTF-8'?>" +
		                                 "<ns1:focus.web.ajax.ExportStoriesAction xmlns:ns1='urn:Gemini'>" +
		                                 "<projectId datatype='String' value='" + exportStoryDialog.selectedProjectId + "' />" +
 		                                 "<backlogId datatype='String' value='" + exportStoryDialog.selectedBacklogId + "' />" +
		                                 "</ns1:focus.web.ajax.ExportStoriesAction>" ;
	    							 
	            document.forms[0].submit();							
		
		},
		//////////////////////////////////////////////////    
        // ---------- Public methods ----------
        //////////////////////////////////////////////////    
         showExportStoryDialog: function(projectId,backlogId) {			

	 	    // initialize data
    		exportStoryDialog.selectedProjectId = projectId;
            exportStoryDialog.selectedBacklogId = backlogId;
			exportStoryDialog.createDialog();
			
			 //  initialize dialog
            exportStoryDialog.dlgFormCtrl.form.reset();   

            exportStoryDialog.dialog.setTitle(EXPORTSTORYLabels.EXPORTSTORY_DLG_TITLE);
			//select XMl by default
			exportStoryDialog.xmlRadio.onPressed('xmlRadio');
			exportStoryDialog.bafoRadio.onUnPressed('bafoRadio');
			document.getElementById('xmlMsg_Span').style.color= EXPORTSTORYLabels.SELECTED_LINK_COLOR;
			document.getElementById('bafoMsg_Span').style.color=EXPORTSTORYLabels.UNSELECTED_LINK_COLOR;
		 //  show
           exportStoryDialog.dialog.show();		
        }};