<cfsilent><!--- dispatch --->
<cfimport prefix="m" taglib="../lib"/>
<cfimport prefix="c" taglib="../lib/controls"/>

<cfparam name="ATTRIBUTES.usePRG" type="boolean" default="Yes"/>
<cfparam name="ATTRIBUTES.pageInfo" type="struct"/>
<cfparam name="ATTRIBUTES.status" type="struct"/>


<cfif structKeyExists(ATTRIBUTES,"id")>
	<cfset id=#ATTRIBUTES.id#/>
<cfelse>
	<cfparam name="ATTRIBUTES.data" type="struct"/>
	<cfset id=#ATTRIBUTES.data[ATTRIBUTES.pageInfo.entity &"_id"]#/>
</cfif>

<cfparam name="ATTRIBUTES.defaultBackUrl" type="string" default="#ATTRIBUTES.pageInfo.entity#_ls.cfm"/>
<cfparam name="ATTRIBUTES.queryString" type="string" default="#ATTRIBUTES.pageInfo.key#=#id#"/><!---works only for entities with simple integer primary key--->
<cfparam name="ATTRIBUTES.trackOut" type="string" default=""/>
<cfparam name="ATTRIBUTES.idAttributesOut" type="string" default=""/><!---works only for entities with simple integer primary key--->

<m:track 
	thisURL="#request.thisPage#?#ATTRIBUTES.queryString#"
	defaultBackUrl="#ATTRIBUTES.defaultBackUrl#"
	output="tr"
/>

<!--- route --->
<cfif ATTRIBUTES.usePRG AND !ATTRIBUTES.status.errorState>
	<!--- PRG pattern--->
	<cfif structKeyExists(CALLER, "save")>
		<m:location url="#tr.selfUrl#"/>
	</cfif>
</cfif>

<cfif structKeyExists(CALLER, "saveAndClose") AND !ATTRIBUTES.status.errorState>
	<m:location url="#tr.backUrl#"/>
</cfif>

<cfif structKeyExists(CALLER, "saveAndNew") AND !ATTRIBUTES.status.errorState>
	<m:location url="#tr.selfUrl#&doClone"/><!--- должен содержать Query String, чтобы указать ключ, иначе смысла нет--->
</cfif>
<!---/route --->

<cfset ATTRIBUTES.pageInfo.track=#tr#/>
<cfset ATTRIBUTES.pageInfo.status=#ATTRIBUTES.status#/><!---Передаем статус в pageInfo--->

<cfif len(ATTRIBUTES.trackOut)>
	<cfset "CALLER.#ATTRIBUTES.trackOut#"=#tr#/>
</cfif>

<cfif len(ATTRIBUTES.idAttributesOut)>
	<cfset "CALLER.#ATTRIBUTES.idAttributesOut#.cfsqltype"="cf_sql_integer"/>
	<cfset "CALLER.#ATTRIBUTES.idAttributesOut#.value"=#id#/>
	<cfset "CALLER.#ATTRIBUTES.idAttributesOut#.null"=#!isNumeric(id)#/>
</cfif>

<cfexit method="exittag"/>
</cfsilent>