Hide Text on scrolling down bottom of the page, Sencha 3 ExtJS - extjs

I am adding a text "Please scroll down" to the Terms and Conditions web page and the text should hide after reaching the bottom of the page. I created a container that shows the text on the entire page under View (Sencha Architect) but not sure how to hide it after scrolling to the bottom. I am trying to create a controller action under Controllers but it's not working. Attached is the code for TermsConditions controller. ItemID of the container containing text is scrollContainer
onAgreeClick: function(button, e, eOpts) {
var store = Ext.data.StoreManager.lookup('UserObjectStore');
var match = store.first(),
showAnnouncements = match.get('announcementPageToVisit');
if (showAnnouncements) {
button = this.getBtnAnnouncements();
} else {
button = this.getBtnCustomerSearch();
}
this.simulateHeaderButtonClick(button);
Ext.Ajax.request({
url: '../abc/services/users/saveUser',
method: 'GET',
headers: { 'Content-Type': 'application/json' },
success: function (response, action) {
},
failure: function (response, action) {
}
});
},
onDisagreeClick: function(button, e, eOpts) {
Ext.Msg.confirm('','You must agree to the Terms and Conditions in order to continue. Press YES to go back or NO to exit.',
function(answer) {
if (answer === "no") {
var h = abc.app.getController('HeaderButton');
h.terminateApp('ok', null, null);
}
}
);
},
BackToTaC: function(button, e, eOpts) {
this.getTermsBtnContainer().hide();
this.getTermsBackContainer().show();
this.getScrollContainer().hide();
this.getBtnAnnouncements().toggle();
this.getBody().getLayout().setActiveItem(6);
},
var me = this;
dataview.getEl().on('scroll', function(e, t) {
if(t.scrollHeight - t.scrollTop - t.clientHeight === 0) {
}
});// I already tried to hide under this but it doesn't work
onTermsBeforeShow: function(component, eOpts) {
var me = this;
var termsView = component.down('dataview');
var termsStore = termsView.getStore();
termsStore.getProxy().actionMethods = {create: 'POST', read: 'POST', update: 'POST', destroy: 'POST'};
termsStore.load();
},

I have had similar requirements for Extjs Panel and I handled them by getting the height of the grid and comparing the height with the current Y Position of the grid.
In the panel page , I had
var toBeAbsoluted = this.getHeight() / 95 * 100; // approximation 95% seemed optimum in my case
if(this.getY() >= (this.getHeight() - toBeAbsoluted ))
buttonToHide.hide()

Related

Shopware - Extjs - How to get value of the table element?

For some time I have a problem with my Shopware plugin. I extended article listWindow, added a column with checkbox. When customer clicks on checkbox I need to get article number that is in another column.
The way I first did it seems unreliable because it depends on position of a columns that can change.
//{block name="backend/article_list/view/main/grid"}
//{$smarty.block.parent}
//{namespace name=backend/article_list/main}
Ext.define('Shopware.apps.ArticleList.view.main.etsy_attribute.Grid', {
override: 'Shopware.apps.ArticleList.view.main.Grid',
...
getToolbar: function () {
var me = this, buttons;
buttons = me.callParent();
me.equaliseEtsyBtn = Ext.create('Ext.button.Button', {
text: 'Etsy equalise',
iconCls: 'sprite-drive-upload',
onClick: function () {
var i,
recPerPage = me.items.items[0].all.elements,
for (i = 0; i < recPerPage.length; i++) {
var productNumber = recPerPage[i].children[2].innerText;
if( recPerPage[i].children[numOfChildren].children[0].children[0].checked === true) {
Ext.Ajax.request({
method: 'POST',
url: '{url controller="someController" action="someAction"}',
params: Object.assign({
productNumber: productNumber
}),
success: function (res) {
//var parsed = JSON.parse(res.responseText);
},
failure: function () {
}
});
} else {
});
}
}
}
});
buttons.add(me.equaliseEtsyBtn);
return buttons;
},
})
What is bad here is this:
recPerPage[i].children[numOfChildren].children[0].children[0].checked === true
And similar lines. How to get value I need in some smarter and more accurate way?
Alse tried with .down and .up
Please give me some direction!

getting the right colIdx in ExtJs

ExtJs is a new world for me. I hope I can get the problem explained very well.
I have a grid with different editor columns. If I change one and save it, I have to change the output.
I do it with
e.row.cells[e.colIdx].childNodes[0].innerText = '{s name=column/express/yes}JA{/s}';
e.row.cells[e.colIdx].classList.add("warning");
If I change 2 different fields at the same time, e.colIdx does not fit anymore to the right column.
Is there a getter or anything else to get the column of a special grid column ?
Here is the complete code
onSavePosition: function(editor, e, store, options) {
var me = this,positionStore;
if (((e.newValues.md_express != e.originalValues.md_express) && e.record.internalId > 0)
|| e.newValues.md_supplier != e.originalValues.md_supplier) {
var customCallback = function (position, success) {
Ext.Ajax.request({
method: 'POST',
url: '{url controller=AttributeData action=saveData}',
params: {
_foreignKey: e.record.internalId,
_table: 's_order_details_attributes',
__attribute_md_express: Number(e.newValues.md_express),
__attribute_md_supplier: e.newValues.md_supplier
},
success:function(response){
var t=this;
me.getOrderList().store.load();
var selectedRowIndex=e.grid.getSelectionModel().getCurrentPosition().row;
var selectedRowRecord=e.grid.getStore().getAt(selectedRowIndex);
selectedRowRecord.set('md_express',e.newValues.md_express);
selectedRowRecord.set('md_supplier',e.newValues.md_supplier);
selectedRowRecord.commit();
debugger;
if((e.newValues.md_express != e.originalValues.md_express)) {
if (e.newValues.md_express == true) {
e.row.cells[e.colIdx].childNodes[0].innerText = '{s name=column/express/yes}JA{/s}';
e.row.cells[e.colIdx].classList.add("warning");
} else {
e.row.cells[e.colIdx].childNodes[0].innerText = '{s name=column/express/no}NEIN{/s}';
e.row.cells[e.colIdx].classList.remove("warning");
}
}
}
});
};
options.callback = customCallback;
}
me.callParent([editor, e, store, options]);
}
my solution is
var colIdx = me.getColumnIndex(editor.grid,'md_express');
getColumnIndex: function(grid, dataIndex) {
gridDataIndices = Ext.Array.pluck(grid.columns, 'dataIndex');
return Ext.Array.indexOf(gridDataIndices, dataIndex);
}
this sends back the column index of the given column in my grid.
Found here
how to find column index using dataIndex Extjs 4

Refreshing gridpanel after removing newly added record from store

How do I remove a newly added row from a gridpanel? The gridpanel is bound to a store.
I use:
store.remove(record);
store.sync();
It works fine on existing records in the grid, the record is removed from the grid directly, but when I add a record and want to remove it right away, it isn't 'removed' form the grid.
The api is called, so the record is 'removed from the database' and the record is indeed gone when I do e.g. a browser refresh.
Does anyone knows how this works? Thanks in advance.
Store configurations
Ext.define('Iziezie.store.animal.doggywood.animal', {
extend: 'Iziezie.store.animal.animal',
model: 'Iziezie.model.animal.doggywood.animal',
proxy: {
type: 'baseProxy',
api: {
create: '../php/api/doggywood_animals.php?request=create',
read: '../php/api/doggywood_animals.php?request=read',
update: '../php/api/doggywood_animals.php?request=update',
destroy: '../php/api/doggywood_animals.php?request=destroy'
}
}
});
New records is added by form:
var store = gridpanel.getStore();
var model = Ext.ModelMgr.getModel(store.model);
var record = model.create();
store.insert(0, record);
...
frm.loadRecord(record);
On form submit
frm.updateRecord();
var record = frm.getRecord();
record.save();
On remove:
var sm = gridpanel.getSelectionModel();
var record = sm.getLastSelected();
var store = gridpanel.getStore();
store.remove(record);
store.sync();
To force a visual refresh on the grid, you can just call
myGridPanel.getView().refresh();
But this shouldn't be required, the grid should just show whatever is in your store. Can you post a full code sample of what you are doing?
try this to create a new record to grid panel using row editing:
createRecord: function() {
var model = Ext.ModelMgr.getModel('EKOJS.model.m_yourmodel');
var r = Ext.ModelManager.create({
id: '',
text: ''
}, model);
this.getYourgridaliasview().getStore().insert(0, r);
this.getYourgridaliasview().rowEditing.startEdit(0, 0);
},
and to remove the selected record in your grid panel :
deleteRecord: function(dataview, selections) {
var getstore = this.getYourgridaliasview().getStore();
var selection = this.getYourgridaliasview().getSelectionModel().getSelection()[
0];
if (selection) {
Ext.Msg.confirm('Confirmation',
'Are you sure to delete this data: id = "' + selection.data
.id + '"?', function(btn) {
if (btn == 'yes') {
getstore.remove(selection);
getstore.sync();
}
});
}
},
and, the important thing always reload your store after creating record like this :
Ext.Ajax.request({
method: 'POST',
url: '../php/api/doggywood_animals.php?request=create',
params: {
data: jsonData
},
success: function(response) {
e.store.reload({
callback: function() {
var newRecordIndex = e.store.findBy(
function(record, id) {
if (record.get('id') === e.record
.data.id) {
return true;
}
return false;
});
/* me.grid.getView().select(recordIndex); */
me.grid.getSelectionModel().select(
newRecordIndex);
}
});
}
});
The listener of after edit in rowediting plugin i use is like this below :
'afteredit': function(editor, e) {
var me = this;
if ((/^\s*$/).test(e.record.data.id)) {
Ext.Msg.alert('Peringatan', 'Kolom "id" tidak boleh kosong.');
return false;
}
/* e.store.sync();
return true; */
var jsonData = Ext.encode(e.record.data);
Ext.Ajax.request({
method: 'POST',
url: '../php/api/doggywood_animals.php?request=create',
params: {
data: jsonData
},
success: function(response) {
e.store.reload({
callback: function() {
var newRecordIndex = e.store.findBy(
function(record, id) {
if (record.get('id') ===
e.record.data.id
) {
return true;
}
return false;
});
/* me.grid.getView().select(recordIndex); */
me.grid.getSelectionModel().select(
newRecordIndex);
}
});
}
});
return true;
}
May be a little help for you.

extjs 4 loadRecord() very slow

I have a datagrid, and on double click of any record in the grid, I am navigating to formPanel which has about 100+ display fields in it.
My issue here is that, the loadRecord takes a lot of time, close to 20 secs to load all these 100+ display fields.
Is there any faster way to do this? Any help or ideas is much appreciated.
Ext.Ajax.request({
url: someurl
method: 'POST',
params: {
params: params
},
success: function(response) {
var responseData = response.responseText;
var doc = new DOMParser().parseFromString(responseData, "text/xml");
store.loadRawData(doc);
var formPanel = Ext.getCmp('FormPanel');
var formPanelData = store.getAt(0);
console.log("Its fast upto here!!");
formPanel.getForm().loadRecord(formPanelData);
console.log("Takes upto 20 secs to get here!!");
var vp = Ext.getCmp('viewport');
vp.getLayout().setActiveItem('formPanel');
}
});
Suspend layouts during the load:
Ext.suspendLayouts();
form.loadRecord(foo);
Ext.resumeLayouts(true);
Even for filtering out data in Tree Panel in EXTJs 4.1.3
Suspend layout drastically increases your searching speed. see below :
applyFilterFn: function(filterCmp) {
Ext.suspendLayouts(); // Adding by Lokesh to speed up
var me = this;
var root = this.getTreeStore().getRootNode();
me.registerFilter(filterCmp);
me.filtered = true;
if(typeof filterCmp.beforeFilter === 'function'){
filterCmp.beforeFilter();
}
root.cascadeBy(function(node){
if(node.isRoot() && !me.rootVisible){ return; }//skip invisible root
var nid = (me.useDataIds===true)? node.data.id:node.id;
if(typeof me.filterNodeHash[nid]==='undefined'){
me.filterNodeHash[nid] = [];
}
if(filterCmp.filterFn.call(filterCmp,node)){
me.filterNodeHash[nid][filterCmp.id] = true;
"+me.filterNodeHash[nid][filterCmp.id]);
}else{
me.filterNodeHash[nid][filterCmp.id] = false;
//console.log("value of "+node.data.task+", "+me.filterNodeHash[nid][filterCmp.id]);
}
},me);
root.eachChild(function(childNode){
Ext.fly(me.getNodeByRecord(childNode)).setDisplayed(true);
});
root.eachChild(function(childNode){
me.applyFilters(childNode,0); ////////added changed code
});
// console.log("root node id "+this.getTreeStore().getRootNode().getId().data.task);
Ext.resumeLayouts(true); // put it to resume your css layouts
if(typeof filterCmp.afterFilter === 'function'){
filterCmp.afterFilter();
}
},// applyFilterFn you may call from a differnt javascript file

How to update an extjs window on its button click

Currently i am facing the following problem.
I am displaying after successful call of this ajax request.
function callDesignWindow(){
var serviceType = $("#serviceType").val();
alert(serviceType);
var ptId = $("#pt_id").val();
alert(ptId);
getAjaxPage({
url : "/ajax/NewEform/design.do?serviceType=" + serviceType +"&ptId =" + ptId,
successCallback: function (data) {
showDesignWindow(data);
}
});
searchVisible = true;
}
function showDesignWindow(htmlData){
alert(" In the show Design Window");
var designWindow = new Ext.Window({
title: "E-Form Design Phase",
width:650,
autoHeight: true,
id:'designWindow',
html: htmlData,
closable: false,
y: 150,
listeners: {
beforeclose: function () {
searchVisible = false;
}
},
buttons: [
{
text: 'Add Control', handler: function() {
saveFormControl();
}
},
{
text:'Customize', handler: function() {
designWindow.hide();
callCustomWindow();
}
}
]
});
designWindow.show(this);
}
function saveFormControl(){
alert(" add control button clicked");
if (!validateEformData()) return false;
formname= $("#formname").val();
alert(formname);
controlType= $("#controlType").val();
alert(controlType);
label= $("#labelname").val();
alert(label);
dataType= $("#dataType").val();
required= $("#required").val();
serviceType= $("#serviceType").val();
ptId = $("#ptId").val();
if(controlType == 3){
var itemList = [];
$("#selectedItemLists option").each(function(){
itemList.push($(this).val());
});
}
data = "eform_name=" + formname + "&control=" + controlType + "&serviceType=" + serviceType +"&ptId=" + ptId +"&labelName=" +label+ "&dataType=" +dataType+"&required="+required+"&items="+itemList;
alert(data);
$.ajax( {
type : "POST",
url : "/ajax/eformDetails/save.do",
data : data,
cache : false,
dataType : "text/html",
timeout: 40000,
error: function (xhr, err)
{
resolveAjaxError(xhr, err);
},
success : function(data) {
// Ext.getCmp('designWindow').close();
// showDesignWindow(data);
}
});
}
Now on success call of the ajax call ("/ajax/eformDetails/save.do") i want to update the designWindow and reset the values.
please help me in this.
If you want to be able to to manipulate our designWindow after you have already created it, you will need to either maintain a reference to it somewhere, or take advantage of the Ext.getCmp method (I would recommend the latter. For example, in your success function:
success: function () {
var myWindow = Ext.getCmp('designWindow');
//do whatever changes you would like to your window
}

Resources