PDA

View Full Version : [CLOSED] GridPanel + FormPanel updateRecord issue



John_Writers
Apr 22, 2013, 10:36 AM
Hi,
I'm creating a CRUD page.

Behavior of the page:
With a button I open a window with a formpanel.
I change the data on the form panel and, when I click on save button I want to update the data with webservice call.

I think that the real problem is that I don't update the record in the store.

How can I update the record in the store?

The insertRecord is working well, but I cannot update..

Thank you for your help!

This is the code

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterDefault.Master" AutoEventWireup="true"
CodeBehind="Tanks.aspx.cs" Inherits="Cryo.Web.CrioWizard.Forms.Tanks" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>


<asp:Content ID="Content2" ContentPlaceHolderID="CPH_Center" runat="server">

<script type="text/javascript" language="javascript">

function OpenDetail(record, rowIndex){
var win_det = <%=wndAddNew.ClientID %>;
var fp = <%=frmTank.ClientID %>;
edit_index = rowIndex;
win_det.show();
fp.getForm().loadRecord(record);
}

var addRecord = function (form, grid) {
if (!form.getForm().isValid()) {
Ext.net.Notification.show({
iconCls : "icon-exclamation",
html : "Form is invalid",
title : "Error"
});

return false;
}

grid.store.insert(0, new TankDTO(form.getForm().getValues()));
form.getForm().reset();
};

var updateRecord = function (form) {
if (form.getForm()._record == null) {
return;
}

if (!form.getForm().isValid()) {
Ext.net.Notification.show({
iconCls : "icon-exclamation",
html : "Form is invalid",
title : "Error"
});
return false;
}

form.getForm().updateRecord();
};


</script>

<ext:Store ID="st_tanks" runat="server" AutoLoad="true" AutoSync="true">
<Proxy>
<ext:AjaxProxy>
<ActionMethods Read="GET" Update="GET"></ActionMethods>
<API
Read="../WebService/WCF_DataAccess.svc/GetTanksDTO"
Create="../WebService/WCF_DataAccess.svc/AddTankDTO"
Update="../WebService/WCF_DataAccess.svc/UpdateTankDTO"
/>
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter Root="d" Encode="true" />
</Writer>
</ext:AjaxProxy>

</Proxy>

<Model>
<ext:Model ID="mdlTank" runat="server" IDProperty="ID_TANK" Name="TankDTO">
<Fields>
<ext:ModelField Name="ID_Tank" Type="Int" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="Description" Type="String" />

<ext:ModelField Name="ID_TANK_TYPE" Type="Int" Mapping="ID_TANK_TYPE" />
<ext:ModelField Name="TankType" Type="String" Mapping="TankType" />

<ext:ModelField Name="Enabled" Type="Boolean" Mapping="Enabled" DefaultValue="false" />

<ext:ModelField Name="ID_ROOM" Type="Int" Mapping="ID_ROOM" />
<ext:ModelField Name="Room" Type="String" Mapping="Room" />

<ext:ModelField Name="ID_LINE" Type="Int" Mapping="ID_LINE" />
<ext:ModelField Name="Line" Type="String" Mapping="Line" />

<ext:ModelField Name="Description4Report" Type="String" />
<ext:ModelField Name="ShowCoverState" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowEVState" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowLevel" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowTemp1" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowTemp2" Type="Boolean" DefaultValue="false" />

<ext:ModelField Name="ID_TANK_GROUP" Type="Int" Mapping="ID_TANK_GROUP" />
<ext:ModelField Name="TankGroup" Type="String" Mapping="TankGroup" />

<ext:ModelField Name="ADDRESS_IP" Type="String" Mapping="ADDRESS_IP" />
<ext:ModelField Name="ADDRESS_IP_1" Type="String" Mapping="ADDRESS_IP_1" />

<ext:ModelField Name="COM_PORT" Type="String" Mapping="COM_PORT" />
<ext:ModelField Name="COM_PORT_1" Type="String" Mapping="COM_PORT_1" />
<ext:ModelField Name="Node_Port" Type="String" Mapping="Node_Port" />
<ext:ModelField Name="PlatinumDoorNodePort" Type="String" Mapping="PlatinumDoorNodePort" />

<ext:ModelField Name="UseLineIP" Type="Boolean" Mapping="UseLineIP" DefaultValue="false" />

</Fields>
</ext:Model>
</Model>
<Listeners>
<Exception Handler="
var error = operation.getError(),
message = Ext.isString(error) ? error : ('(' + error.status + ')' + error.statusText);
Ext.net.Notification.show({
iconCls : 'icon-exclamation',
html : message,
title : 'EXCEPTION',
autoScroll : true,
hideDelay : 5000,
width : 300,
height : 200
});" />
</Listeners>
</ext:Store>
<ext:GridPanel ID="gp_Tanks" runat="server" StoreID="st_tanks" Title="Tank List" Height="400" Flex="1" Region="Center">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" ColumnID="ID_Tank" DataIndex="ID_Tank" Hidden="true" />
<ext:Column runat="server" ColumnID="Name" Header="Name" Locked="true" Sortable="false" DataIndex="Name" />
<ext:Column runat="server" ColumnID="Description" Header="Description" Align="Left" DataIndex="Description" />

<ext:Column runat="server" ColumnID="ID_TANK_TYPE" DataIndex="ID_TANK_TYPE" Hidden="true" />
<ext:Column runat="server" ColumnID="TankType" Header="Tank Type" Align="Left" DataIndex="TankType" />

<ext:CheckColumn runat="server" ColumnID="Enabled" Header="Enabled" DataIndex="Enabled" />

<ext:Column runat="server" ColumnID="ID_ROOM" DataIndex="ID_ROOM" Hidden="true" />
<ext:Column runat="server" ColumnID="Room" Header="Room" Align="Left" DataIndex="Room" />

<ext:Column runat="server" ColumnID="ID_LINE" DataIndex="ID_LINE" Hidden="true" />
<ext:Column runat="server" ColumnID="Line" Header="Line" Align="Left" DataIndex="Line" />

<ext:Column runat="server" ColumnID="ID_TANK_GROUP" DataIndex="ID_TANK_GROUP" Hidden="true" />
<ext:Column runat="server" ColumnID="TankGroup" Header="Tank Group" Align="Left" DataIndex="TankGroup" />

<ext:Column runat="server" ColumnID="Description4Report" Header="Description4Report" Align="Left" DataIndex="Description4Report" Hidden="true" />

<ext:CheckColumn runat="server" ColumnID="ShowCoverState" Header="ShowCoverState" DataIndex="Enabled" />
<ext:CheckColumn runat="server" ColumnID="ShowEVState" Header="ShowEVState" DataIndex="ShowEVState" />
<ext:CheckColumn runat="server" ColumnID="ShowLevel" Header="ShowLevel" DataIndex="ShowLevel" />
<ext:CheckColumn runat="server" ColumnID="ShowTemp1" Header="ShowTemp1" DataIndex="ShowTemp1" />
<ext:CheckColumn runat="server" ColumnID="ShowTemp2" Header="ShowTemp2" DataIndex="ShowTemp2" />

<ext:Column ID="ADDRESS_IP" runat="server" ColumnID="ADDRESS_IP" Header="ADDRESS_IP" Align="Left" DataIndex="ADDRESS_IP" />
<ext:Column ID="ADDRESS_IP_1" runat="server" ColumnID="ADDRESS_IP_1" Header="ADDRESS_IP_1" Align="Left" DataIndex="ADDRESS_IP_1" />
<ext:Column ID="COM_PORT" runat="server" ColumnID="COM_PORT" Header="COM_PORT" Align="Left" DataIndex="COM_PORT" />
<ext:Column ID="COM_PORT_1" runat="server" ColumnID="COM_PORT_1" Header="COM_PORT_1" Align="Left" DataIndex="COM_PORT_1" />
<ext:Column ID="Node_Port" runat="server" ColumnID="Node_Port" Header="Node_Port" Align="Left" DataIndex="Node_Port" />
<ext:Column ID="PlatinumDoorNodePort" runat="server" ColumnID="PlatinumDoorNodePort" Header="PlatinumDoorNodePort" Align="Left" DataIndex="PlatinumDoorNodePort" />
<ext:CheckColumn ID="UseLineIP" runat="server" ColumnID="UseLineIP" Header="UseLineIP" DataIndex="UseLineIP" />
</Columns>
</ColumnModel>


<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single">
<Listeners>
<Select Handler="#{frmTank}.getForm().loadRecord(record);" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
<Buttons>
<ext:Button ID="btnAdd" Icon="ApplicationAdd" Text="Add new" runat="server" OnClientClick="#{wndAddNew}.show();#{frmTank}.getForm().reset();# {btnAddSave}.setVisible(true);#{btnUpdateSave}.set Visible(false);#{wndAddNew}.setTitle('Add new');">
</ext:Button>
<ext:Button ID="btnEdit" Icon="ApplicationEdit" Text="Edit selected" runat="server" OnClientClick="#{wndAddNew}.show();#{frmTank}.loadRecord(#{gp_Tan ks}.getSelectionModel().getSelection());#{btnAddSa ve}.setVisible(false);#{btnUpdateSave}.setVisible( true);#{wndAddNew}.setTitle('Edit selected');">
</ext:Button>
</Buttons>

</ext:GridPanel>

<ext:Window
ID="wndAddNew"
runat="server"
Title=""
Icon="Application"
Height="400"
Width="400"
BodyStyle="background-color: #fff;"
BodyPadding="5"
Modal="true"
Hidden="true"
AutoScroll="true"
>
<Content>
<ext:FormPanel ID="frmTank" runat="server" Header="false" Padding="5" ButtonAlign="Right">
<Items>


<ext:FieldSet ID="fsTankDescription"
runat="server"
ColumnWidth="0.4"
Title="Information"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="240" />
<ext:Parameter Name="LabelWidth" Value="90" />
</Defaults>
<Items>
<ext:TextField ID="txtName"
Name="Name"
runat="server"
FieldLabel="Name" />
<ext:TextField ID="txtDescription" Name="Description" runat="server" FieldLabel="Description" />

<ext:ComboBox ID="cboTankType" runat="server" Name="ID_TANK_TYPE" AutoSelect="true" FieldLabel="Tank Type" ValueField="ID_TANK_TYPE" DisplayField="Name" >
<Store>
<ext:Store runat="server" ID="TankTypeStore" AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetTankTypes">
<Reader><ext:JsonReader Root="d"></ext:JsonReader></Reader>
<Writer><ext:JsonWriter AllowSingle="true" /></Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="TankTypeModel" runat="server" IDProperty="ID_TANK_TYPE">
<Fields>
<ext:ModelField Name="ID_TANK_TYPE" Type="Int" Mapping="ID_TANK_TYPE" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsTankPosition"
runat="server"
ColumnWidth="0.4"
Title="Position"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="240" />
<ext:Parameter Name="LabelWidth" Value="90" />
</Defaults>
<Items>
<ext:ComboBox ID="cboRoom" runat="server" Name="ID_ROOM" AutoSelect="true" FieldLabel="Room" ValueField="ID_ROOM" DisplayField="Name" >
<Store>
<ext:Store
runat="server"
ID="stRooms"
AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetRooms">
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter AllowSingle="true" />
</Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="mdlRooms" runat="server" IDProperty="ID_ROOM">
<Fields>
<ext:ModelField Name="ID_ROOM" Type="Int" Mapping="ID_ROOM" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>

<ext:ComboBox ID="cboLine" runat="server" Name="ID_LINE" AutoSelect="true" FieldLabel="Nitrogen Line" ValueField="ID_LINE" DisplayField="Name" >
<Store>
<ext:Store
runat="server"
ID="stLine"
AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetLines">
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter AllowSingle="true" />
</Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="mdlLines" runat="server" IDProperty="ID_LINE">
<Fields>
<ext:ModelField Name="ID_LINE" Type="Int" Mapping="ID_LINE" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>

<ext:ComboBox ID="cboTankGroup" runat="server" Name="ID_TANK_GROUP" AutoSelect="true" FieldLabel="Tank Filling Group"
ValueField="ID_TANK_GROUP" DisplayField="Name" >
<Store>
<ext:Store
runat="server"
ID="stTanksGroups"
AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetTankGroups">
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter AllowSingle="true" />
</Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="mdlTankGroups" runat="server" IDProperty="ID_TANK_GROUP">
<Fields>
<ext:ModelField Name="ID_TANK_GROUP" Type="Int" Mapping="ID_TANK_GROUP" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsAddress"
runat="server"
ColumnWidth="0.4"
Title="Address"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="240" />
<ext:Parameter Name="LabelWidth" Value="90" />
</Defaults>
<Items>
<ext:TextField ID="txtADDRESS_IP" Name="ADDRESS_IP" runat="server" FieldLabel="IP Address" />
<ext:TextField ID="txtADDRESS_IP_1" Name="ADDRESS_IP_1" runat="server" FieldLabel="IP Address 2" />
<ext:TextField ID="txtCOM_PORT" Name="COM_PORT" runat="server" FieldLabel="COM_PORT" />
<ext:TextField ID="txtCOM_PORT_1" Name="COM_PORT_1" runat="server" FieldLabel="COM_PORT_1" />
<ext:TextField ID="txtNode_Port" Name="Node_Port" runat="server" FieldLabel="Node_Port" />
<ext:TextField ID="txtPlatinumDoorNodePort" Name="PlatinumDoorNodePort" runat="server" FieldLabel="PlatinumDoorNodePort" />
<ext:Checkbox ID="chkUseLineIP" Name="UseLineIP" runat="server" FieldLabel="UseLineIP" />

</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsDataShow"
runat="server"
ColumnWidth="0.4"
Title="Data Show on Panel"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="240" />
<ext:Parameter Name="LabelWidth" Value="90" />
</Defaults>
<Items>
<ext:Checkbox ID="chkShowTemp" Name="ShowTemp1" runat="server" FieldLabel="Show Temperature"></ext:Checkbox>
<ext:Checkbox ID="chkShowLevel" Name="ShowLevel" runat="server" FieldLabel="Show Level"></ext:Checkbox>
<ext:Checkbox ID="chkShowCover" Name="ShowCoverState" runat="server" FieldLabel="Show Cover"></ext:Checkbox>
<ext:Checkbox ID="chkShowEV" Name="ShowEVState" runat="server" FieldLabel="Show Electrovalve"></ext:Checkbox>

</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsTankManagement"
runat="server"
ColumnWidth="0.4"
Title="Management"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="240" />
<ext:Parameter Name="LabelWidth" Value="90" />
</Defaults>
<Items>
<ext:Checkbox ID="chkEnable" Name="Enabled" runat="server" FieldLabel="Enabled"></ext:Checkbox>
</Items>
</ext:FieldSet>

</Items>
<Buttons>
<ext:Button ID="btnAddSave" runat="server" Text="Add" Icon="Disk">
<Listeners>
<Click Handler="addRecord(#{frmTank}, #{gp_tanks});#{wndAddNew}.setVisible(false);#{st_t anks}.load();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnUpdateSave" runat="server" Text="Update" Icon="Disk">
<Listeners>
<Click Handler="updateRecord(#{frmTank}, #{gp_tanks});#{wndAddNew}.setVisible(false);#{st_t anks}.load();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Content>
</ext:Window>
</asp:Content>

Daniil
Apr 22, 2013, 1:04 PM
Hi John,

It can look something like this.

Example

var form = this.up('form').getForm(), // get the basic form
record = form.getRecord(); // get the underlying model instance

if (form.isValid()) { // make sure the form contains valid data before submitting
form.updateRecord(record); // update the record with the form data
record.save({ // save the record to the server
success: function(user) {
Ext.Msg.alert('Success', 'User saved successfully.')
},
failure: function(user) {
Ext.Msg.alert('Failure', 'Failed to save user.')
}
});
} else { // display error alert if the data is invalid
Ext.Msg.alert('Invalid Data', 'Please correct form errors.')
}

Daniil
Apr 22, 2013, 1:28 PM
Well, you seems do the same. And yes, you don't need to call the save method explicitly since you are using AutoSync="true".

Ok, what does happen here?

form.getForm().updateRecord();

Does it initiate an update request? Please ensure there are no any JavaScript errors.

John_Writers
Apr 22, 2013, 2:08 PM
Hi,
I modified my code as follow



<%@ Page Title="" Language="C#" MasterPageFile="~/MasterDefault.Master" AutoEventWireup="true"
CodeBehind="Tanks.aspx.cs" Inherits="Cryo.Web.CrioWizard.Forms.Tanks" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>


<asp:Content ID="Content2" ContentPlaceHolderID="CPH_Center" runat="server">

<script type="text/javascript" language="javascript">

function OpenDetail(record, rowIndex){
var win_det = <%=wndAddNew.ClientID %>;
var fp = <%=frmTank.ClientID %>;
edit_index = rowIndex;
win_det.show();
fp.getForm().loadRecord(record);
}

var addRecord = function (form, grid) {
if (!form.getForm().isValid()) {
Ext.net.Notification.show({
iconCls : "icon-exclamation",
html : "Form is invalid",
title : "Error"
});

return false;
}

grid.store.insert(0, new TankDTO(form.getForm().getValues()));
form.getForm().reset();
};

var updateRecord = function () {
var form = this.up('form').getForm(); // get the basic form
record = form.getRecord(); // get the underlying model instance

if (form.isValid()) { // make sure the form contains valid data before submitting
form.updateRecord(record); // update the record with the form data
record.save({ // save the record to the server
success: function(user) {
Ext.Msg.alert('Success', 'User saved successfully.')
},
failure: function(user) {
Ext.Msg.alert('Failure', 'Failed to save user.')
}
});
} else { // display error alert if the data is invalid
Ext.Msg.alert('Invalid Data', 'Please correct form errors.')
}
};


</script>

<ext:Store ID="st_tanks" runat="server" AutoLoad="true" AutoSync="true">
<Proxy>
<ext:AjaxProxy>
<ActionMethods Read="GET" Update="GET"></ActionMethods>
<API
Read="../WebService/WCF_DataAccess.svc/GetTanksDTO"
Create="../WebService/WCF_DataAccess.svc/AddTankDTO"
Update="../WebService/WCF_DataAccess.svc/UpdateTankDTO"
/>
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter Root="d" Encode="true" />
</Writer>
</ext:AjaxProxy>

</Proxy>

<Model>
<ext:Model ID="mdlTank" runat="server" IDProperty="ID_TANK" Name="TankDTO">
<Fields>
<ext:ModelField Name="ID_Tank" Type="Int" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="Description" Type="String" />

<ext:ModelField Name="ID_TANK_TYPE" Type="Int" Mapping="ID_TANK_TYPE" />
<ext:ModelField Name="TankType" Type="String" Mapping="TankType" />

<ext:ModelField Name="Enabled" Type="Boolean" Mapping="Enabled" DefaultValue="false" />

<ext:ModelField Name="ID_ROOM" Type="Int" Mapping="ID_ROOM" />
<ext:ModelField Name="Room" Type="String" Mapping="Room" />

<ext:ModelField Name="ID_LINE" Type="Int" Mapping="ID_LINE" />
<ext:ModelField Name="Line" Type="String" Mapping="Line" />

<ext:ModelField Name="Description4Report" Type="String" />
<ext:ModelField Name="ShowCoverState" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowEVState" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowLevel" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowTemp1" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="ShowTemp2" Type="Boolean" DefaultValue="false" />

<ext:ModelField Name="ID_TANK_GROUP" Type="Int" Mapping="ID_TANK_GROUP" />
<ext:ModelField Name="TankGroup" Type="String" Mapping="TankGroup" />

<ext:ModelField Name="ADDRESS_IP" Type="String" Mapping="ADDRESS_IP" />
<ext:ModelField Name="ADDRESS_IP_1" Type="String" Mapping="ADDRESS_IP_1" />

<ext:ModelField Name="COM_PORT" Type="String" Mapping="COM_PORT" />
<ext:ModelField Name="COM_PORT_1" Type="String" Mapping="COM_PORT_1" />
<ext:ModelField Name="Node_Port" Type="String" Mapping="Node_Port" />
<ext:ModelField Name="PlatinumDoorNodePort" Type="String" Mapping="PlatinumDoorNodePort" />

<ext:ModelField Name="UseLineIP" Type="Boolean" Mapping="UseLineIP" DefaultValue="false" />

</Fields>
</ext:Model>
</Model>
<Listeners>
<Exception Handler="
var error = operation.getError(),
message = Ext.isString(error) ? error : ('(' + error.status + ')' + error.statusText);
Ext.net.Notification.show({
iconCls : 'icon-exclamation',
html : message,
title : 'EXCEPTION',
autoScroll : true,
hideDelay : 5000,
width : 300,
height : 200
});" />
</Listeners>
</ext:Store>
<ext:GridPanel ID="gp_Tanks" runat="server" StoreID="st_tanks" Title="Tank List" Height="600" Flex="1" Region="Center">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" ColumnID="ID_Tank" DataIndex="ID_Tank" Hidden="true" />
<ext:Column runat="server" ColumnID="Name" Header="Name" Locked="true" Sortable="false" DataIndex="Name" />
<ext:Column runat="server" ColumnID="Description" Header="Description" Align="Left" DataIndex="Description" />

<ext:Column runat="server" ColumnID="ID_TANK_TYPE" DataIndex="ID_TANK_TYPE" Hidden="true" />
<ext:Column runat="server" ColumnID="TankType" Header="Tank Type" Align="Left" DataIndex="TankType" />

<ext:CheckColumn runat="server" ColumnID="Enabled" Header="Enabled" DataIndex="Enabled" />

<ext:Column runat="server" ColumnID="ID_ROOM" DataIndex="ID_ROOM" Hidden="true" />
<ext:Column runat="server" ColumnID="Room" Header="Room" Align="Left" DataIndex="Room" />

<ext:Column runat="server" ColumnID="ID_LINE" DataIndex="ID_LINE" Hidden="true" />
<ext:Column runat="server" ColumnID="Line" Header="Line" Align="Left" DataIndex="Line" />

<ext:Column runat="server" ColumnID="ID_TANK_GROUP" DataIndex="ID_TANK_GROUP" Hidden="true" />
<ext:Column runat="server" ColumnID="TankGroup" Header="Tank Group" Align="Left" DataIndex="TankGroup" />

<ext:Column runat="server" ColumnID="Description4Report" Header="Description4Report" Align="Left" DataIndex="Description4Report" Hidden="true" />

<ext:CheckColumn runat="server" ColumnID="ShowCoverState" Header="ShowCoverState" DataIndex="Enabled" />
<ext:CheckColumn runat="server" ColumnID="ShowEVState" Header="ShowEVState" DataIndex="ShowEVState" />
<ext:CheckColumn runat="server" ColumnID="ShowLevel" Header="ShowLevel" DataIndex="ShowLevel" />
<ext:CheckColumn runat="server" ColumnID="ShowTemp1" Header="ShowTemp1" DataIndex="ShowTemp1" />
<ext:CheckColumn runat="server" ColumnID="ShowTemp2" Header="ShowTemp2" DataIndex="ShowTemp2" />

<ext:Column ID="ADDRESS_IP" runat="server" ColumnID="ADDRESS_IP" Header="ADDRESS_IP" Align="Left" DataIndex="ADDRESS_IP" />
<ext:Column ID="ADDRESS_IP_1" runat="server" ColumnID="ADDRESS_IP_1" Header="ADDRESS_IP_1" Align="Left" DataIndex="ADDRESS_IP_1" />
<ext:Column ID="COM_PORT" runat="server" ColumnID="COM_PORT" Header="COM_PORT" Align="Left" DataIndex="COM_PORT" />
<ext:Column ID="COM_PORT_1" runat="server" ColumnID="COM_PORT_1" Header="COM_PORT_1" Align="Left" DataIndex="COM_PORT_1" />
<ext:Column ID="Node_Port" runat="server" ColumnID="Node_Port" Header="Node_Port" Align="Left" DataIndex="Node_Port" />
<ext:Column ID="PlatinumDoorNodePort" runat="server" ColumnID="PlatinumDoorNodePort" Header="PlatinumDoorNodePort" Align="Left" DataIndex="PlatinumDoorNodePort" />
<ext:CheckColumn ID="UseLineIP" runat="server" ColumnID="UseLineIP" Header="UseLineIP" DataIndex="UseLineIP" />
</Columns>
</ColumnModel>


<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single">
<Listeners>
<Select Handler="#{frmTank}.getForm().loadRecord(record);" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
<Buttons>
<ext:Button ID="btnAdd" Icon="ApplicationAdd" Text="Add new" runat="server" OnClientClick="#{wndAddNew}.show();#{frmTank}.getForm().reset();# {btnAddSave}.setVisible(true);#{btnUpdateSave}.set Visible(false);#{wndAddNew}.setTitle('Add new');">
</ext:Button>
<ext:Button ID="btnEdit" Icon="ApplicationEdit" Text="Edit selected" runat="server" OnClientClick="#{wndAddNew}.show();#{frmTank}.loadRecord(#{gp_Tan ks}.getSelectionModel().getSelection());#{btnAddSa ve}.setVisible(false);#{btnUpdateSave}.setVisible( true);#{wndAddNew}.setTitle('Edit selected');">
</ext:Button>
</Buttons>

</ext:GridPanel>

<ext:Window
ID="wndAddNew"
runat="server"
Title=""
Icon="Application"
Height="500"
Width="600"
BodyPadding="5"
Modal="true"
Hidden="true"
AutoScroll="true"
>
<Content>
<ext:FormPanel ID="frmTank" runat="server" Header="false" Padding="5" ButtonAlign="Right">
<Items>

<ext:FieldSet ID="fsTankDescription"
runat="server"
ColumnWidth="0.4"
Title="Information"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:TextField ID="txtName"
Name="Name"
runat="server"
FieldLabel="Name" />
<ext:TextField ID="txtDescription" Name="Description" runat="server" FieldLabel="Description" />

<ext:ComboBox ID="cboTankType" runat="server" Name="ID_TANK_TYPE" AutoSelect="true" FieldLabel="Tank Type" ValueField="ID_TANK_TYPE" DisplayField="Name" >
<Store>
<ext:Store runat="server" ID="TankTypeStore" AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetTankTypes">
<Reader><ext:JsonReader Root="d"></ext:JsonReader></Reader>
<Writer><ext:JsonWriter AllowSingle="true" /></Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="TankTypeModel" runat="server" IDProperty="ID_TANK_TYPE">
<Fields>
<ext:ModelField Name="ID_TANK_TYPE" Type="Int" Mapping="ID_TANK_TYPE" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsTankPosition"
runat="server"
ColumnWidth="0.4"
Title="Position"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:ComboBox ID="cboRoom" runat="server" Name="ID_ROOM" AutoSelect="true" FieldLabel="Room" ValueField="ID_ROOM" DisplayField="Name" >
<Store>
<ext:Store
runat="server"
ID="stRooms"
AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetRooms">
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter AllowSingle="true" />
</Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="mdlRooms" runat="server" IDProperty="ID_ROOM">
<Fields>
<ext:ModelField Name="ID_ROOM" Type="Int" Mapping="ID_ROOM" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>

<ext:ComboBox ID="cboLine" runat="server" Name="ID_LINE" AutoSelect="true" FieldLabel="Nitrogen Line" ValueField="ID_LINE" DisplayField="Name" >
<Store>
<ext:Store
runat="server"
ID="stLine"
AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetLines">
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter AllowSingle="true" />
</Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="mdlLines" runat="server" IDProperty="ID_LINE">
<Fields>
<ext:ModelField Name="ID_LINE" Type="Int" Mapping="ID_LINE" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>

<ext:ComboBox ID="cboTankGroup" runat="server" Name="ID_TANK_GROUP" AutoSelect="true" FieldLabel="Tank Filling Group"
ValueField="ID_TANK_GROUP" DisplayField="Name" >
<Store>
<ext:Store
runat="server"
ID="stTanksGroups"
AutoLoad="true">
<Proxy>
<ext:RestProxy Url="../WebService/WCF_DataAccess.svc/GetTankGroups">
<Reader>
<ext:JsonReader Root="d"></ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter AllowSingle="true" />
</Writer>
</ext:RestProxy>
</Proxy>
<Model>
<ext:Model ID="mdlTankGroups" runat="server" IDProperty="ID_TANK_GROUP">
<Fields>
<ext:ModelField Name="ID_TANK_GROUP" Type="Int" Mapping="ID_TANK_GROUP" />
<ext:ModelField Name="Name" Type="String" Mapping="Name" />
<ext:ModelField Name="Description" Type="String" Mapping="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsAddress"
runat="server"
ColumnWidth="0.4"
Title="Address"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:TextField ID="txtADDRESS_IP" Name="ADDRESS_IP" runat="server" FieldLabel="IP Address" />
<ext:TextField ID="txtADDRESS_IP_1" Name="ADDRESS_IP_1" runat="server" FieldLabel="IP Address 2" />
<ext:TextField ID="txtCOM_PORT" Name="COM_PORT" runat="server" FieldLabel="COM_PORT" />
<ext:TextField ID="txtCOM_PORT_1" Name="COM_PORT_1" runat="server" FieldLabel="COM_PORT_1" />
<ext:TextField ID="txtNode_Port" Name="Node_Port" runat="server" FieldLabel="Node_Port" />
<ext:TextField ID="txtPlatinumDoorNodePort" Name="PlatinumDoorNodePort" runat="server" FieldLabel="PlatinumDoorNodePort" />
<ext:Checkbox ID="chkUseLineIP" Name="UseLineIP" runat="server" FieldLabel="UseLineIP" />

</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsDataShow"
runat="server"
ColumnWidth="0.4"
Title="Data Show on Panel"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:Checkbox ID="chkShowTemp" Name="ShowTemp1" runat="server" FieldLabel="Show Temperature"></ext:Checkbox>
<ext:Checkbox ID="chkShowLevel" Name="ShowLevel" runat="server" FieldLabel="Show Level"></ext:Checkbox>
<ext:Checkbox ID="chkShowCover" Name="ShowCoverState" runat="server" FieldLabel="Show Cover"></ext:Checkbox>
<ext:Checkbox ID="chkShowEV" Name="ShowEVState" runat="server" FieldLabel="Show Electrovalve"></ext:Checkbox>

</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsTankManagement"
runat="server"
ColumnWidth="0.4"
Title="Management"
MarginSpec="0 0 0 10"
ButtonAlign="Right">
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:Checkbox ID="chkEnable" Name="Enabled" runat="server" FieldLabel="Enabled"></ext:Checkbox>
</Items>
</ext:FieldSet>

</Items>
<Buttons>
<ext:Button ID="btnAddSave" runat="server" Text="Add" Icon="Disk">
<Listeners>
<Click Handler="addRecord(#{frmTank}, #{gp_tanks});#{wndAddNew}.setVisible(false);#{st_t anks}.load();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnUpdateSave" runat="server" Text="Update" Icon="Disk">
<Listeners>
<Click Handler="updateRecord();#{wndAddNew}.setVisible(false);#{st _tanks}.load();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Content>
</ext:Window>
</asp:Content>




but I get this error

Microsoft JScript runtime error: Object doesn't support property or method 'up'

executing the following line

var form = this.up('form').getForm();

What is the up function? I've never used it before..

Thank you.

John_Writers
Apr 22, 2013, 3:12 PM
Hi,

I changed my code in this way:


<ext:Button ID="btnUpdateSave" runat="server" Text="Update" Icon="Disk">
<Listeners>
<Click Handler="#{frmTank}.getForm().updateRecord();#{wndAddNew}.s etVisible(false);#{st_tanks}.load();" />
</Listeners>
</ext:Button>


but
I get the following error..

Microsoft JScript runtime error: Unable to get value of the property 'items': object is null or undefined


executing this code:


updateRecord : function (record) {
if (!record) {
record = this._record;
}

var fields = record.fields.items, <------------------------------------------------------------
values = this.getFieldValues(false, true),
obj = {},
i = 0,
len = fields.length,
name;

for (; i < len; ++i) {
name = fields[i].name;

if (values.hasOwnProperty(name)) {
obj[name] = values[name];
}
}

record.beginEdit();
record.set(obj);
record.endEdit();

return this;
},

Thank you for your help!

Daniil
Apr 22, 2013, 6:06 PM
Could you, please, provide a runnable test case?

John_Writers
Apr 23, 2013, 8:37 AM
How can I provide a runnable test case?

This is a big page..

Daniil
Apr 23, 2013, 10:17 AM
You can simplify it step by step.
How to prepare a sample (http://forums.ext.net/showthread.php?13672&p=56687&viewfull=1#post56687)

John_Writers
Apr 23, 2013, 3:18 PM
Thank you for your help.

I make some changes in the updateRecord Method


var updateRecord = function (form) {
if (form.getForm()._record == null) {
return;
}

if (!form.getForm().isValid()) {
Ext.net.Notification.show({
iconCls : "icon-exclamation",
html : "Form is invalid",
title : "Error"
});
return false;
}

form.getForm().updateRecord(form.getForm()._record[0]);
};

Now it works.

Have a good day!