PageRenderTime 564ms CodeModel.GetById 169ms app.highlight 101ms RepoModel.GetById 243ms app.codeStats 0ms

/src/main/webapp/public/js/home.js

http://thoughtsite.googlecode.com/
JavaScript | 129 lines | 93 code | 5 blank | 31 comment | 29 complexity | 142f1424f8a4ac59791d511d96e98bdc MD5 | raw file
  1/* Copyright 2010 Google Inc.
  2 * 
  3 * Licensed under the Apache License, Version 2.0 (the "License");
  4 * you may not use this file except in compliance with the License.
  5 * You may obtain a copy of the License at
  6 * 
  7 *      http://www.apache.org/licenses/LICENSE-2.0
  8 * 
  9 * Unless required by applicable law or agreed to in writing, software
 10 * distributed under the License is distributed on an "AS IS" BASIS.
 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 * See the License for the specific language governing permissions and
 13 * limitations under the License
 14 */
 15
 16/**
 17 * file is responsible to handle all javascript tasks on home page
 18 * require jquery 1.3.2 
 19 */
 20// onload set form focus validations
 21google.setOnLoadCallback(function() {
 22    ie.Login.setLoggedinUserCallback('home.handleSaveIdeaForm');
 23	// categories required for the form
 24    ie.loadCategories('category', ''/*selected cat id*/);
 25    // on focus idea title
 26    $('#title').focus(function () {
 27  	    if($('#title').val() == 'Idea Title') {
 28  	        $('#title').val('');
 29  	    }
 30    });
 31    $('#title').blur(function () {
 32  	    if($('#title').val() == '') {
 33  	        $('#title').val('Idea Title');
 34  	    }
 35    });
 36    $('#description').focus(function () {
 37  	    if($('#description').val() == 'Description') {
 38  	        $('#description').val('');
 39  	    }
 40    });
 41    $('#description').blur(function () {
 42  	    if($('#description').val() == '') {
 43  	        $('#description').val('Description');
 44  	    }
 45    });
 46    $('#tags').focus(function () {
 47  	    if($('#tags').val() == 'Tags') {
 48  	        $('#tags').val('');
 49  	    }
 50    });
 51    $('#tags').blur(function () {
 52  	    if($('#tags').val() == '') {
 53  	        $('#tags').val('Tags');
 54  	    }
 55    });
 56    // set description char limit to 3000 chars
 57    $('#description').limit('3000','#charsLeft');
 58    
 59    // Put autocomplete functionality on Tags
 60    $("#tags").autocomplete(ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'tags/suggest/'), {
 61        width: 200,
 62        dataType: "json",
 63        parse: function(handle) {
 64            if(handle.viewStatus.status == ie.config.SUCCESS) {
 65                return $.map(handle.viewStatus.data.tags, function(row) {
 66                    return {
 67                        data: row,
 68                        value: row.key,
 69                        result: row.title
 70                    }
 71                });
 72            }
 73            else {
 74                return;
 75            }
 76        },
 77        formatItem: function(row) {
 78            return row.title;
 79        },
 80        multiple: true,
 81        matchContains: false,
 82        highlight: false,
 83        formatted: false
 84    });
 85});
 86
 87
 88/**
 89 * handle save idea on the basis of user login as login is must for save idea 
 90 */
 91home.handleSaveIdeaForm = function (isUserLoggedIn) {
 92    if(isUserLoggedIn) {
 93        $('#btnSaveIdea').unbind('click');
 94        $('#btnSaveIdea').bind('click', function () {
 95            if($.trim($('#title').val()) == '' || $.trim($('#title').val()) == 'Idea Title') {
 96                $('#errDisplay').html('Please add Idea title');
 97                $('#errDisplay').show();
 98                return;
 99            }
100            if($('#description').val() == 'Description') {
101                $('#description').val('');
102            }
103            if($('#tags').val() == 'Tags') {
104                $('#tags').val('');
105            }
106            $('#submitIdeaForm').submit();
107        });
108    }
109    else {
110        $('#btnSaveIdea').unbind('click');
111        $('#btnSaveIdea').click(function () {
112        	ie.Login.showLoginPopup();
113        });
114    }
115}
116
117/**
118 * validate save idea form
119 * @return boolean
120 */
121home.validateForm = function () {
122    // only title field is required to save an idea
123    if($.trim($('#title').val()) == '' || $.trim($('#title').val()) == 'Idea Title') {
124        $('#errDisplay').html('Please add Idea title');
125        $('#errDisplay').show();
126        return false;
127    }
128    return true;
129}