это keeprecord.js, в котором находится js-каталог cake webroot, а также папка extjs 4, также помещенная в ту же директорию. Доступ к extjs 4 через этот js-файл
код: maintainrecord.js
function getBaseURL() {
var url = location.href;
window.location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));
if (baseURL.indexOf('http://localhost') != -1) {
var url = location.href;
var pathname = location.pathname;
var index1 = url.indexOf(pathname);
var index2 = url.indexOf("/", index1 + 1);
var baseLocalUrl = url.substr(0, index2);
return baseLocalUrl + "/";
}
else {
return baseURL + "/";
}
}
var pathname=location.pathname;
var myarray = pathname.split("/");
window.id=myarray[4];
Ext.onReady(function(){
var r=getBaseURL();
// Define our data model
Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: [
'id',
'notes',
'asset_id',
'date_',
'maint_picture',
'maint_condition1',
'maint_condition2',
'maint_condition3',
'maint_condition4'
]
}
);
//alert('th correct');
//cake php crud and create the Data Store
var store = new Ext.data.Store
({
proxy: {
type: 'ajax',
api: {
create: { url: r+'toolbar2/tbl_maintenance_records/create', method: 'POST' },
read: { url: r+'toolbar2/tbl_maintenance_records/index?id='+window.id, method: 'GET'},
update: { url: r+'toolbar2/tbl_maintenance_records/update', method: 'POST' },
destroy: { url: r+'toolbar2/tbl_maintenance_records/delete', method: 'POST' }
},
reader: {
type: 'json', // We expect the server to give us a JSON string as a response
root: 'users'
}
},
autoLoad: true,
autoSave: false,
listeners: {
exception: function(proxy, type, action, o, result, records)
{
if (type = 'remote')
{
Ext.Msg.alert("Could not " + action, result.raw.message);
}
else if (type = 'response')
{
Ext.Msg.alert("Could not " + action, "Server's response could not be decoded");
}
else
{
Ext.Msg.alert("Store sync failed", "Unknown error");
}
}
}
});
//alert('crud correct');
function syncStore(rowEditing, changes, r, rowIndex) {
store.save();
}
//create drop down elements
var cond1 = new Ext.data.SimpleStore({
fields: ['maint_condition1'], data : [['Excellent'],['Poor'],['New'],['good'],['scrap']]});
var cond2 = new Ext.data.SimpleStore({
fields: ['maint_condition2'], data : [['Excellent'],['Poor'],['New']]});
var cond3 = new Ext.data.SimpleStore({
fields: ['maint_condition3'], data : [['New'],['Excellent']]});
var cond4 = new Ext.data.SimpleStore({
fields: ['maint_condition4'], data : [['New'],['Excellent'],['good'],['Poor'],['scrap']]});
//ready store
//var cb_select2 =new Ext.grid.CheckboxSelectionModel();
var asset_edit = new Ext.form.TextField();
var notes_edit = new Ext.form.TextField();
var date_edit = new Ext.form.DateField({format: 'm/d/Y'});
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false,
saveText: 'Save',
listeners: {
afteredit: syncStore
}
});
var cond1_edit = new Ext.form.DateField({format: 'combo'});
//var sm = Ext.grid.getSelectionModel();
//alert('before grid');
//Grid for show data
var grid = Ext.create('Ext.grid.Panel', {
id:'grid1',
renderTo: document.body,
extend: 'Ext.form.ComboBox',
plugins:[rowEditing],
frame: true,
height:140,
width:950,
enableColumnMove: false,
store: store,
columns: [
{header: "Asset ID", dataIndex: 'asset_id'},
{header: "Maint. ID", dataIndex: 'id'},
{header: "Date", dataIndex: 'date_',editor:date_edit},
{header: "Notes", dataIndex: 'notes',editor: notes_edit},
{header: "Maint_condition1", dataIndex: 'maint_condition1', sortable: true,width: 120,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: cond1,
valueField: 'maint_condition1',
displayField: 'maint_condition1',
triggerAction: 'all',
editable: false
}
)},
{header: "Maint_condition2", dataIndex: 'maint_condition2', sortable: true,width: 120,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: cond2,
valueField: 'maint_condition2',
displayField: 'maint_condition2',
triggerAction: 'all',
editable: false
}
)},
{header: "Maint_condition3", dataIndex: 'maint_condition3', sortable: true,width: 120,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: cond3,
valueField: 'maint_condition3',
displayField: 'maint_condition3',
triggerAction: 'all',
editable: false
}
)},
{header: "Maint_condition4", dataIndex: 'maint_condition4', sortable: true,width: 120,
editor: new Ext.form.ComboBox({
allowBlank: false,
mode: 'local',
store: cond4,
valueField: 'maint_condition4',
displayField: 'maint_condition4',
triggerAction: 'all',
editable: false
}
)}
],
tbar: [{
text: 'Add Record',
icon: 'http://localhost/toolbar2/app/webroot/images/table_add.png',
cls: 'x-btn-text-icon',
handler: function() {
grid.getStore().insert(0, new Employee({
id: 0,
notes: 'New Notes',
asset_id: window.id,
//maint_condition3: false
}));
rowEditing.startEdit(0,0);
}
},{
text: 'Remove Record',
icon: 'http://localhost/toolbar2/app/webroot/images/table_delete.png',
cls: 'x-btn-text-icon',
handler: function() {
var sm = grid.getSelectionModel();
rowEditing.cancelEdit();
store.remove(sm.getSelection());
if (store.getCount() > 0)
{
sm.select(0);
}
}
}]
});
//alert('after grid');
//alert('gffgf');
//alert(r);
});
добавление и удаление этого приложения, оно не работает, помогите мне решить мою проблему, .....