Monday, November 17, 2014

Angular directive for prompting unsaved changes

0 comments
The best thing about AngularJs is directives, which gives a whole new perspective on customizability and reusability.

One instance that I use andular directives is prompting unsaved changes dialog when doing a back in a detail page. For solving this I coded a small directive which basically hooks in the back button.

For my scenario, in the detail pages there can be multiple forms and editable kendo grids. So I cannot use form's dirty attribute that is exposed by Angular. Therefore I written a checkDirty() method in each controller where I implement this, which encapsulates the logic which decides if there any unsaved changes.

The above method is ideal for me but not for everybody. Some other ways of implementing this is to hook the directive to the form or use directly $dirty attributes available in forms.

Below is the directive that I used to achieve this functionality.

app.directive('ngUnsavedChanges', ['$modal', '$timeout', ($modal, $timeout) => {
        return {
            restrict: 'A',
            link: (scope, element, attrs) => {
                element.bind('click', () => {
                    scope.checkDirty();
                    if (!scope.dirty) { // If view is not dirty do back
                        scope.$apply(attrs.backAction);
                        return;
                    }
                    var modalInstance = $modal.open({
                        templateUrl: 'app/views/savechanges.html',
                        controller: 'CancelConfirmModal',
                        size: 'sm'
                    });
                    modalInstance.result.then(result => {
                        $timeout(() => {
                            if (result === 'save') {
                            scope.$apply(attrs.saveAction);
                            }
                            else if (result === 'dontsave') {
                                scope.$apply(attrs.backAction);
                            }
                        }); 
                    });
                });
            }
        }
    }]);


You can use the directive like this.




Monday, September 21, 2009

Browsing World Wide Web from the terminal

2 comments
We usually browse internet from browsers which have fancy gui, buttons, gestures, shortcuts. Chrome, Firefox, Safari, Internet Explorer are few of them.
Being a geek we love to do things the hard way :-) Simply because it is fun!!
How about browsing internet from the plain old terminal? Amazing huh!! w3m is installed default by ubuntu which provides browsing internet from terminal
try it becoz it is FUN!

w3m in action -->

Sunday, September 20, 2009

Awesome photos that I have taken

0 comments
Below is my picasa web albums link, please comment if you like the photos! :-)
http://picasaweb.google.com/tharidufernando/StarPhotos#

Thursday, August 27, 2009

Sinhaly the wave robot

0 comments
Hello everybody,
This week I was free so I started a little wave project. To who don't know what is wave it is a new tool for communication and collaboration on the web. It is initiative from Google and will be available for public later this year. To learn more about wave go to this link.
Google wave is still in developer preview stage which have lots of bugs :-( You can get a invite from this link.
To whom who have google wave accounts my address is tharidu@wavesandbox.com
So let's start,
Google wave allows developers to use and enhance it through the APIs available. They are Robots, Gadgets and Embed. Well I developed a small functioning robot called "sinhaly" which enables user to use English-Sinhala transliteration easily. So if you type mama it will convert it to මම. It runs in the cloud and to use it you will have to add sinhaly ( sinhaly@appspot.com ) as a participant.
Sinhaly was written in python a
nd uses unicode standard to render Sinhala fonts. The algorithm was derived from UCSC Language Technology Research Laborotary's Real Time Unicode Converter.

Sinhaly in action :-)

Hope you enjoyed my post, please leave a comment!

Wednesday, August 19, 2009

How to rearm Windows 7

0 comments
Windows 7 is not yet released but the RTM version is available at MSDN. The intial trial period of Windows 7 is 30 days. However this can be extended upto 120 days!
This is legal also!!

"slmgr.vbs –rearm"


Enter the above command at a command prompt and restart. This command must be used when the trial day counter almost zero. The above command will give 30 days and can be entered 3 times.

wave

0 comments


Sunday, July 19, 2009

Techකතා Live: 24වන සජීවී වැඩසටහන හා පැන-විසඳුම්

0 comments
Techකතා Live: 24වන සජීවී වැඩසටහන හා පැන-විසඳුම්

  • High Quality (STEREO) 64Kbps (Broadband අන්තර්ජාල සම්බන්ධතා සදහා)


    [Download MP3 (32MB) or Ogg (31MB)]


  • Low Quality (STEREO) 32Kbps (Dial-up අන්තර්ජාල සම්බන්ධතා සදහා)


    [Download MP3 (16MB) or Ogg (21MB)]

  •