Subversion Repositories SmartDukaan

Rev

Rev 14849 | Rev 19564 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function(){
        if($('.brandedit').length){
                $('.brandedit').on('click',function(){
                        var that = $(this);
                        var value = 0;
                        if($(this).prop('checked')){
                                value = 1;
                        }
                        $.post($(this).data('url'),{'id':$(this).data('id'),'displayed_in_preference_page':value},function(data){
                                if(data.success){$(that).parent().append('Done');};
                        })
                });
        }
    $('.edit').editable(base_url+'admin/'+controller+'/update/',{
        onsubmit: function(settings, td) {            
            var r = confirm('Copy to catalog?');
            if (r == true) {                
                $(td).data('multi',1);
            } else {
                $(td).data('multi',0);
            }
                var input = $(td).find('input');
                var original = input.val();
                if (isNumeric(original)) {
                    console.log("Validation correct");
                    return true;
                } else {
                    console.log("Validation failed. Ignoring");
                    input.css('background-color','#c00').css('color','#fff');
                    return false;
                }
            },
        indicator : 'Saving...',
        tooltip   : 'Click to edit...',
        submit : 'OK',
        submitdata : function(value, settings) {
               return {oid: $(this).data('oid'),multi: $(this).data('multi')};
           }
    });
    $('.sqlslecter').on('click',function(){
        $('#UserSql').html($(this).parent().siblings('.updatesql').html());
    })
    $('.pushtoalll').on('click',function(){
        var that = $(this);
        $('.userIds').each(function(){
                $(this).prop('checked',$(that).prop('checked'));
        })
    });
    $('.notifyusers').on('click',function(){
        if($('#UserMessage').val().length == 0 || $('#UserMessage').val()==''){
                alert('Enter a message first');
                return false;
        }else{
                $('#UserPushForm').submit();
        }
    })    
    $('#MasterDataCategoryId').on('change',function(){
        console.log($('#MasterDataCategoryId option:selected').text());
        $('#MasterDataCategory').val($('#MasterDataCategoryId option:selected').text());
    });
    $('#MasterDataSourceId').on('change',function(){
        console.log($("#MasterDataSourceId option:selected").text());
        $('#MasterDataSource').val($("#MasterDataSourceId option:selected").text());
        $('#MasterDataSecondaryIdentifier').prop('required',false);
        if($(this).val()==3){
            $('#MasterDataSecondaryIdentifier').prop('required','required');
        }
    });        
    $('#MasterDataInStock').on('change',function(){
        console.log($('#MasterDataInStock option:selected').text());
        $('#MasterDataStockStatus').val($('#MasterDataInStock option:selected').text());
    });  
    $('#NotificationRuleType').on('change',function(){
        if($('#NotificationRuleType option:selected').text() =='Popup'){
            $('#NotificationRulePopupDisplayCount').prop('disabled',false);
            $('#NotificationRulePopupDisplayInterval').prop('disabled',false);
            $('#NotificationRulePopupType').prop('disabled',false);
        }else{
            $('#NotificationRulePopupDisplayCount').prop('disabled',true);
            $('#NotificationRulePopupDisplayInterval').prop('disabled',true);
            $('#NotificationRulePopupType').prop('disabled',true);
        }
    })
});
function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}