<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="new_workspace" version="1.0" basedir="" xmlform_type="NORMAL" width="430px" ajaxSubmit="true" in_progress="status_in_progress" callback="status_create">
  <NEW_WORKSPACE type="title">
    <en><![CDATA[New Workspace]]></en>
  </NEW_WORKSPACE>
  <NW_TITLE type="text" size="30" maxlength="13" validate="Login" defaultValue="sample" style="width:100%;">
    <en><![CDATA[Name]]></en>
  </NW_TITLE>
  <DB type="subtitle">
    <en><![CDATA[Database Options]]></en>
  </DB>
  <AO_DB_WF type="text" size="30" maxlength="16" validate="Login" defaultValue="wf_sample" style="width:100%;">
    <en><![CDATA[Workflow Database:]]></en>
  </AO_DB_WF>
  <AO_DB_RB type="text" size="30" maxlength="16" validate="Login" defaultValue="rb_sample" style="width:100%;">
    <en><![CDATA[Rbac Database:]]></en>
  </AO_DB_RB>
  <AO_DB_RP type="text" size="30" maxlength="16" validate="Login" defaultValue="rp_sample" style="width:100%;">
    <en><![CDATA[Report Database:]]></en>
  </AO_DB_RP>
  <AO_DB_DROP type="checkbox">
    <en><![CDATA[Drop database if exist]]></en>
  </AO_DB_DROP>
  <WS type="subtitle">
    <en><![CDATA[Workspace Administrator]]></en>
  </WS>
  <NW_USERNAME type="text" size="30" maxlength="32" validate="Any" defaultValue="admin" style="width:100%;">
    <en><![CDATA[Username:]]></en>
  </NW_USERNAME>
  <NW_PASSWORD type="password" size="30" maxlength="20" validate="Any" defaultValue="admin" style="width:100%;">
    <en><![CDATA[Password (admin) <br> (Max. length 20):]]></en>
  </NW_PASSWORD>
  <NW_PASSWORD2 type="password" size="30" maxlength="20" validate="Any" defaultValue="admin" style="width:100%;">
    <en><![CDATA[Re-type Password:]]></en>
  </NW_PASSWORD2>
  <ACTION type="hidden" defaultValue="test"/>
  <NW_SUB type="submit">
    <en><![CDATA[Test]]></en>
  </NW_SUB>
  <JS type="JavaScript"><![CDATA[
    var data = new Array();
    var ed = new Array();
    leimnud.event.add(window,'load',function(){
    data={
		name:new input(getField('NW_TITLE')).setStyle({fontWeight:'bold'}),
		submit:new button(getField('NW_SUB')),
		ao_db_wf:new input(getField('AO_DB_WF')),
		ao_db_rb:new input(getField('AO_DB_RB')),
		ao_db_rp:new input(getField('AO_DB_RP')),
		ao_db_drop:getField('AO_DB_DROP'),
		ao_admin:new input(getField('NW_USERNAME')),
		ao_admin_pass1:new input(getField('NW_PASSWORD')),
		ao_admin_pass2:new input(getField('NW_PASSWORD2')),
		action:getField('ACTION')
	};
	data.reset = data.submit.parentNode.insertBefore(new button(G_STRINGS.ID_RESET, function()
	{
		ed('enable');
		data.submit.value='Test';
		data.action.value='test';
		return false;
	},false,{type:'reset'}),data.submit);
	
	/*data.goto = data.submit.parentNode.appendChild(new button('Open workspace',function()
	{
		window.location="/sys"+data.name.value+"/en/classic/login/login";
		return false;
	},{fontWeight:'bold'},{type:'reset'})).disable();
	*/
	

	data.loader= data.submit.parentNode.appendChild(new DOM('img',{src:'/images/classic/loader_B.gif'},{width:22,height:22,position:'relative',display:'block'}));
	data.loader.setStyle({visibility:'hidden'});

  ed = function(mod)
	{
		data.name[mod]();
		data.ao_db_wf[mod]();
		data.ao_db_rb[mod]();
		data.ao_db_rp[mod]();
		data.ao_admin[mod]();
		data.ao_admin_pass1[mod]();
		data.ao_admin_pass2[mod]();
		data.ao_db_drop.disabled=(mod=='enable')?false:true;
	};

	data.name.focus();
	leimnud.event.add(data.name,'keyup',function(){
		var v = data.name.value;
		data.ao_db_wf.value='wf_'+v;
		data.ao_db_rb.value='rb_'+v;
		data.ao_db_rp.value='rp_'+v;
	});
	data.submit.onmouseup=function()
	{
		ed('disable');
	};
	//data.name.passed();
	
  });
  	function redirectLogin(){
		location.href="/sys"+data.name.value+"/en/classic/login/login";
	}

  	var status_in_progress=function(form)
	{
		data.loader.setStyle({visibility:'visible'});
		data.submit.disable();
		if(data.action.value=='create')
		{
			data.reset.disable();
		}
	};
	var status_create=function(rpc)
	{
		data.loader.setStyle({visibility:'hidden'});
		try{var rp=rpc.xmlhttp.responseText.parseJSON();}catch(e){var rp={result:{}};}
		ed('enable');
		data.name[(rp.result.name['status'])?'passed':'failed']().title=rp.result.name['message'];
		data.ao_db_wf[(rp.result.database.ao.ao_db_wf['status'])?'passed':'failed']().title=rp.result.database.ao.ao_db_wf.message;



		data.ao_db_rb[(rp.result.database.ao.ao_db_rb['status'])?'passed':'failed']().title=rp.result.database.ao.ao_db_rb.message;
		data.ao_db_rp[(rp.result.database.ao.ao_db_rp['status'])?'passed':'failed']().title=rp.result.database.ao.ao_db_rp.message;
		data.ao_admin[(rp.result.admin.username)?'passed':'failed']().title=(rp.result.admin.username)?'OK':'PASSED';
		data.ao_admin_pass1[(rp.result.admin.password)?'passed':'failed']().title=(rp.result.admin.password)?'OK':'PASSED';
		data.ao_admin_pass2[(rp.result.admin.password)?'passed':'failed']().title=(rp.result.admin.password)?'OK':'PASSED';
		data.name.focus();
		data.submit.enable();

		if(rp.created)
		{
			ed('disable');
			data.submit.value=G_STRINGS.ID_CREATE;
			data.submit.setStyle({fontWeight:'bold'});
			data.action.value='create';
		}
		else
		{
			data.submit.setStyle({fontWeight:'normal'});
		}
		if(rp.created && rp.result['action']=='create')
		{
			var confirm = new leimnud.module.app.confirm().make({
		  		label: G_STRINGS.NEW_SITE_SUCCESS +" "+ data.name.value +"<br/>"+ G_STRINGS.NEW_SITE_SUCCESS_CONFIRM+"<br/>"+ G_STRINGS.NEW_SITE_SUCCESS_CONFIRMNOTE,
		    	action: function(){

		    	parent.parent.window.location="/sys"+data.name.value+"/en/classic/login/login";

		 /*  	   if (typeof(window.parent.admToolsContent) != 'undefined'){

					 parent.parent.window.location="/sys"+data.name.value+"/en/classic/login/login";
					} else {
					    setTimeout('redirectLogin()', 1000);
					}*/
				}.extend(this),
				cancel: function(){

					//window.location="../install/newSite?type=blank";
				},
				width:380,
				height:140
		  	});

			data.goto.enable();
			data.submit.disable();
			data.reset.disable();
		}
	};
]]></JS>
</dynaForm>
