Wednesday, March 12, 2014

testing

<script>
alert("hello");
</script>

Friday, November 29, 2013

News for php

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

Monday, September 23, 2013

CSV file download code

Details later,

<?php
if(!empty($_GET['file'])){
    $foo = "some value,another value,last value";
    file_put_contents("File1.csv",$foo);
    @ob_end_clean();
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: attachment; filename=File1.csv");
    header("Cache-control: private");
     header('Pragma: private');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    $new_length = filesize("File1.csv");
    echo $foo;
}else{
    echo "<a href='?file=1'>Click here</a>";
}
?>

Wednesday, September 18, 2013

Javascript objects

In JavaScript, almost everything is an object. All primitive types except null and undefined are treated as objects. They can be assigned properties and they have all characteristics of objects. Javascript is object based programming language (Prototype-based programming). First time when I heard, JS is OO programming, I was surprised and can't find and class, interface, etc such keywords. Later, I found, it's different. See below,
var jsObj = new Object();
jsObj.property1 = "Value1";
jsObj.property2 = "Value2"
That's how we create object and use properties. Alternative way to accessing properties,
myCar["property1"] = "Value1";myCar["property2"] = "Value2"; 
Aren't they associative arrays?Yes, you are right!Javascript Objects are sometimes called associative arrays.
Another way for creating objects in javascript,

var obj = { 'property1':   "Value1",  
            'property1': "Value2"};// property1 can be number, string or identifier
Methods in javascript,
Constructor - function are methods and it's constructor,
function f1(){
  //function itself is a constructor of object
}
Confused?Let's see below,
function Jsobject(pro1, pro2, pro3) {
  this.pro1 = pro1;
  this.pro2 = pro2;
  this.pro3 = pro3;
}
this above means current object (instance). Like this in java and any other object oriented programming.
var myvar = new Jsobject("Value1", "Value2", "Value3");
Isn't myvar is object?So, isn't function constructor?Alternate way to access properties,
myvar.pro1 = "Value1";
It can be chained like,
Vehicle.scooter.numWheels = 2;
What about methods?See below,
var objMethods = {
  method1: function(params) {
    //body of method here
  }
};
You can assign method to an variable. Suppose you defined function with name method1 then you can assign as below,
this.method = method1;
As always more coming soon. Keep coming here.

jQuery background

Before starting learning jQuery, it's helpful to know some following javascript tricks,

Anonymous Functionsg

  • Anonymous functions are nameless function (function having no name).
  •  Anonymous functions are executed as soon as they are downloaded by browser (if they are not within another function).
  • They are in 2 types.
 
 First type, 
(function(){
  //some cool js stuff here.
});
 
Second type (with passing arguments),
(function(args){
  //some cool js stuff here.
})(args); 
//Above last line will pass args. This looks odd having args 2 times. But learning this way is helpful.
 
Eg. 
(function(args){
  alert(args);
})("hi"); 
 Above function will alert hi
 
Other interesting stuff of anonymous functions in javascript,
 
We can pass anonymous function as argument, like we pass int, string, etc.
Eg,
 
function acceptAnonymousFunction(annonymousFunc) {
    // some code here
    annonymousFunc('javascript!');
}

acceptAnonymousFunction(function(arg) {
    alert('Hello '+ arg);
}); 
// alerts 'Hello javascript!'  
Got it! If not re-read it carefully, you will understand it. 
 
Assigning javascript function as variable,
var myfunc = function(args) 
{                     
  //functionality of myfunc here
}
myfunc(args); // this is calling of myfunc
 
Above code will do exactly same as,
function myfunc(args){
  //functionality of myfunc goes here
} 

More interesting stuff...coming soon!!Keep reading.
 

Monday, September 16, 2013

jQuery Tutorial

jQuery Basic
  1. jQuery is free and open source.
  2. jQuery is library of common tasks, re-usable code.
  3. jQuery is cross browser - It means it runs in most of browsers.
  4. Using jQuery you can easily create Progressive enhancement  and Unobtrusive JavaScript*.
  5.  It simplified javascript programming.
  6. It's easy to learn jQuery.
  7. jQuery avoids copy/pasting (re-inventing wheel) tasks.
  8. You can download jQuery from ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js. You can even use following code in your site,
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
    Using above code, you can avoid server load as jQuery will be downloaded from googleapis.com CDN (content delivery network 
  9. jQuery simplifies common tasks like, Ajax, DOM element selections, traversal and manipulation, event handling, popup, and also extensible, etc.
  10. jQuery official sites are -

*Features of Progressive enhancement  and Unobtrusive JavaScript - 
  • Functionality should be separate from presentation. In other words, Javascript code should be separate from html/ css code.
  • Graceful degradation - If browser doesn't support some feature, javascript should not show error. It degrades gracefully.
  • Progressive enhancement - Similar to above. If browser doesn't support, it shouldn't support extra wow animated effects, but shows basic HTML. But in new browsers with greater bandwidths, it shows full featured, wow effect animations. But there should be alternate way to use it for other browsers. (eg. gmail shows basic HTML version during slow connection or in old browsers).
More coming soon. Keep coming this blog. Book mark it.Thanks :)

How to add Javascript in sugarcrm?


Suppose you want to add cases_custom.js in cases module,

Open
custom/modules/Cases/metadata/editviewdefs.php file,

Add following code at right place in above file,

  'includes'=> array(
    array('file'=>'custom/modules/Cases/cases_custom.js'),
  ),


Now create file cases_custom.js inside custom/modules/Cases/metadata/cases_custom.js

That's it. Now write javascript inside,  cases_custom.js