
<div class="container-fluid">
    <div>
        <h3>Store Settings</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Store</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Store Settings</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
        <div class="col-lg-6 col-md-6 pull-left">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Artists Brand Store</h6>

                    <div class="events-settings-alert"></div>
                    <div class="events-settings-test-alert"></div>
                    <form class="events-settings" method="POST">
                        <div class="float-left">
                            <label for="store_system" class="main-label">Brand Store System</label>
                            <br><small class="admin-info">Enable the ability for artistes to sell products related to their song.</small>
                        </div>
                        <div class="form-group float-right switcher">
                            <input type="hidden" name="store_system" value="off" />
                            <input type="checkbox" name="store_system" id="chck-store_system" value="on" <?php echo ($music->config->store_system == 'on') ? 'checked': '';?>>
                            <label for="chck-store_system" class="check-trail"><span class="check-handler"></span></label>
                        </div>
                        <div class="clearfix"></div>
                        <hr>
                        <div class="float-left">
                            <label for="store_review_system" class="main-label">Review Products Before Publish</label>
                            <br><small class="admin-info">Do you want to review products before publihsing?</small>
                        </div>
                        <div class="form-group float-right switcher">
                            <input type="hidden" name="store_review_system" value="off" />
                            <input type="checkbox" name="store_review_system" id="chck-store_review_system" value="on" <?php echo ($music->config->store_review_system == 'on') ? 'checked': '';?>>
                            <label for="chck-store_review_system" class="check-trail"><span class="check-handler"></span></label>
                        </div>
                        <div class="clearfix"></div>
                        <hr>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label main-label">Sales Commission</label>
                                <input type="text" name="store_commission" class="form-control" value="<?php echo ($music->config->store_commission);?>">
                                <small class="admin-info">How much is your commission from each sale? (%)</small>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <input type="hidden" name="hash_id" value="<?php echo createMainSession();?>">
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
$(function() {
    $('.switcher input[type=checkbox]').click(function () {
        var configName = $(this).attr('name');
        var hash_id = $('input[name=hash_id]').val();
        var objData = {};
        if ($(this).is(":checked") === true) {
            objData[configName] = $(this).val();
        }
        else{
            if ($('input[name='+configName+']')[0]) {
                objData[configName] = $($('input[name='+configName+']')[0]).val();
            }
        }
        objData['hash_id'] = hash_id;
        $.post('{{CONFIG ajax_url}}/ap/save-settings', objData);
    });

    var setTimeOutColor = setTimeout(function (){});
    $('select').on('change', function() {
         clearTimeout(setTimeOutColor);
        var thisElement = $(this);
        var configName = thisElement.attr('name');
        var hash_id = $('input[name=hash_id]').val();
        var objData = {};
        objData[configName] = thisElement.val();
        objData['hash_id'] = hash_id;
        thisElement.addClass('warning');
        $.post("{{CONFIG ajax_url}}/ap/save-settings", objData, function (data) {
            if (data.status == 200) {
                thisElement.removeClass('warning');
                thisElement.addClass('success');
            } else {
                thisElement.addClass('error');
            }
            var setTimeOutColor = setTimeout(function () {
                thisElement.removeClass('success');
                thisElement.removeClass('warning');
                thisElement.removeClass('error');
            }, 2000);
        });
    });
    $('input[type=text], input[type=number] , textarea').on('keyup', delay(function() {
            clearTimeout(setTimeOutColor);
            var thisElement = $(this);
            var configName = thisElement.attr('name');
            var hash_id = $('input[name=hash_id]').val();
            var objData = {};
            objData[configName] = this.value;
            objData['hash_id'] = hash_id;
            thisElement.addClass('warning');
            $.post("{{CONFIG ajax_url}}/ap/save-settings", objData, function (data) {
                if (data.status == 200) {
                    thisElement.removeClass('warning');
                    thisElement.addClass('success');
                } else {
                    thisElement.addClass('error');
                }
                var setTimeOutColor = setTimeout(function () {
                    thisElement.removeClass('success');
                    thisElement.removeClass('warning');
                    thisElement.removeClass('error');
                }, 2000);
                //thisElement.focus();
            });
    }, 500));
});






$(function() {
    $('#upload_system_type').change(function(event) {
        if ($(this).val() == 1) {
            $('#p_f_users_').removeClass('hidden');
            $('#all_users_').addClass('hidden');
        }
        else{
            $('#all_users_').removeClass('hidden');
            $('#p_f_users_').addClass('hidden');
        }
    });

    var form_fame_settings = $('form.fame-settings');

    form_fame_settings.ajaxForm({
        url: '{{CONFIG ajax_url}}/ap/save-settings',
        beforeSend: function() {
            form_fame_settings.find('button').text("Please wait");
        },
        success: function(data) {
            if (data.status == 200) {
                form_fame_settings.find('button').text('Save');
                $('.fame-settings-test-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Settings updated successfully</div>');
                setTimeout(function () {
                    $('.fame-settings-test-alert').empty();
                }, 2000);
            }
        }
    });

    var form_lock_settings = $('form.lock-settings');

    form_lock_settings.ajaxForm({
        url: '{{CONFIG ajax_url}}/ap/save-settings',
        beforeSend: function() {
            form_lock_settings.find('button').text("Please wait");
        },
        success: function(data) {
            if (data.status == 200) {
                form_lock_settings.find('button').text('Save');
                $('.lock-settings-test-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Settings updated successfully</div>');
                setTimeout(function () {
                    $('.lock-settings-test-alert').empty();
                }, 2000);
            }
        }
    });

    var form_user_settings = $('form.user-settings');

    form_user_settings.ajaxForm({
        url: '{{CONFIG ajax_url}}/ap/save-settings',
        beforeSend: function() {
            form_user_settings.find('button').text("Please wait");
        },
        success: function(data) {
            if (data.status == 200) {
                form_user_settings.find('button').text('Save');
                $('.user-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Settings updated successfully</div>');
                setTimeout(function () {
                    $('.user-settings-alert').empty();
                }, 2000);
            }
        }
    });

    var ffmpeg_settings = $('form.ffmpeg-settings');
    ffmpeg_settings.ajaxForm({
        url: '{{CONFIG ajax_url}}/ap/save-settings',
        beforeSend: function() {
            ffmpeg_settings.find('.waves-effect').text("Please wait");
        },
        success: function(data) {
            if (data.status == 200) {
                ffmpeg_settings.find('.waves-effect').text('Save');
                $('.ffmpeg-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Settings updated successfully</div>');
                setTimeout(function () {
                    $('.ffmpeg-settings-alert').empty();
                }, 2000);
            }
        }
    });

});
</script>
