Skip to content

Instantly share code, notes, and snippets.

View rattanchauhan's full-sized avatar
🎯
Focusing

Rattan Chauhan rattanchauhan

🎯
Focusing
View GitHub Profile
@rattanchauhan
rattanchauhan / app.js
Last active November 6, 2016 12:45
Adding global exception handler through Sencha Architect.
Ext.Ajax.on({
requestexception: function(dataconn, response, options) {
console.dir(dataconn);
console.dir(response);
console.dir(response.status);
if (response.status === 401) {
me.redirectTo('login');
}
}
});
@rattanchauhan
rattanchauhan / app.js
Last active November 6, 2016 12:45
Setting global default ajax timeout through Sencha Architect
Ext.data.proxy.Server.override ({
timeout: 300000
});
Ext.data.Connection.override({
withCredentials: false,
useDefaultXhrHeader: false,
disableCaching:false,
timeout: 300000
});
@rattanchauhan
rattanchauhan / app.js
Last active November 10, 2016 17:16
Adding a loading spinner at app startup in Sencha Architect
if(Ext.fly('initialLoader')){
Ext.fly('initialLoader').destroy();
}
@rattanchauhan
rattanchauhan / Sencha 4
Created October 7, 2016 07:21
Saving component state in LocalStorage in Sencha Architect
Create a function init under Application and add the below code to initialze a state provider to store states of different components
in the browser's local storage.
// initialize state provided for saving component states
Ext.state.Manager.setProvider(Ext.create('Ext.state.LocalStorageProvider'));
Add the below two configs to the component you want to save the state for.
{
@rattanchauhan
rattanchauhan / ViewController1.js
Last active November 14, 2016 13:23
Adding gmaps to extjs app
addGmap: function (googlemapcontainer, viewModel) {
var mapcontainer = googlemapcontainer.down('#mapcontainer');
googlemapcontainer.setHidden(true);
// remove old map
if(mapcontainer) {
mapcontainer.destroy();
}
// create new map
@rattanchauhan
rattanchauhan / Usage.js
Last active November 16, 2016 06:26
Capturing User details for re-using throughout a Sencha app
onMenuPanelRenderer : function() {
var hasWebRole = User.hasRole(Config.role.web);
var hasAdminRole = User.hasRole(Config.role.admin);
if (hasWebRole) {
// set mentu item visible true based on role
}
if (hasAdminRole) {
// set mentu item visible true based on role
@rattanchauhan
rattanchauhan / app.js
Last active December 19, 2019 17:03
AngularJs | Directive for Auto Focus Next element on Enter
var app = angular.module("myApp", []);
app.directive("moveNextOnEnter", function() {
return {
restrict: "A",
link: function($scope, element) {
element.bind("keyup", function(e) {
if (e.which == 13) {
var $nextElement = element.next();
if($nextElement.length) {
$nextElement[0].focus();
@rattanchauhan
rattanchauhan / formatXml.js
Created November 10, 2016 06:12
Utility method to format an xml string
/*
* Utility method to format an xml string
* text : xml String
* step : no of spaces for indentation
*/
formatXml : function(text,step) {
function createShiftArr(step) {
var space = ' ';
if ( isNaN(parseInt(step)) ) { // argument is string
@rattanchauhan
rattanchauhan / Java8.java
Last active November 24, 2016 17:14
Java8 features in practice
package com.practice.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
@rattanchauhan
rattanchauhan / MainController.js
Last active October 13, 2017 15:13
Securing routes in Extjs 6
Ext.define('App.controller.MainController', {
extend: Ext.app.Controller,
routes: {
'home': {
before: function(action) {
Ext.Ajax.request({
url: Config.endpoints.user,
method: 'GET',
scope: this,
failure: function(data, operation) {