Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

// increase the default animation speed to exaggerate the effect
jQuery.fx.speeds._default = 1000;
$(function() {

        jQuery("#type").change(function(){
                if($(this).val()=='brand'){
                        jQuery("#brand").show();
                        jQuery("#category").hide();
                }else {
                        jQuery("#category").show();
                        jQuery("#brand").hide();
                }
        });
        
        $('.edit-link').live('click', function() {
                //close all the opened synonyms
                $('.edit-cancel:visible').trigger('click');
            var trEle = $(this).closest('tr');
            var key = trEle.find('td.key').html();
            value = trEle.find('td.synonyms').html();
                var type = $("#type").val();
                trEle.find('td.synonyms').html('<textarea rows="2" columns="150" onfocus="this.value=this.value">' + value + '</textarea>');
                trEle.find('a.edit-cancel').show();
                $(this).removeClass("edit-link").addClass("save-link").html("save").click(function(){
                        newValue = trEle.find('td.synonyms').find('textarea').val().replace(/(\s+)?,(\s+)?/g,",");
                        if (newValue.indexOf("\"") != -1 || newValue.indexOf("'") != -1){
                            alert("Single quote or bouble quotes are not allowed");
                                trEle.find('td.synonyms textarea').focus();
                                return false;
                        }

                        if(value != newValue){
                                if(newValue==""){
                                        var conf = confirm("Are you sure you want to empty the value");
                                        if(!conf){
                                                trEle.find('td.synonyms textarea').val(value);
                                                trEle.find('td.synonyms textarea').focus();
                                                return false;
                                        }
                                }
                                jQuery.ajax({
                                        url:"synonym/update",
                                        data: {'key':key, 'value':newValue, 'type':type},
                                        dataType:'json',
                                        success:function(data){
                                                if(data){
                                                        value=newValue;
                                                        trEle.find('a.edit-cancel').trigger('click');
                                                } else {
                                                        alert("Some problem occurred while saving. Please try again");
                                                        trEle.find('td.synonyms textarea').focus();
                                                }
                                        }
                                });
                        }else {
                                alert("No change to save.");
                                trEle.find('td.synonyms textarea').focus();
                        }
                });
                return false;
        });
        $('.edit-cancel').click(function(){
                var trEle = $(this).closest('tr');
                trEle.find('td.synonyms').html(value);
                $(this).hide();
                trEle.find('a.save-link').removeClass("save-link").addClass("edit-link").html("edit").unbind();
                return false;
        });
});