function add_partner(){
   $("#partnerModal").modal('show');
    start_load()
         
            $(".modal-title").text("Add Partner");
            $(".sbtn").text("Save");
            setTimeout(function(){
            end_load();
    },500)
}

function edit_partner(id)
{
    $("#partnerModal").modal('show');
    $.ajax({
        url:  base_url + 'administrator/partners/edit/'+ id,
        type: "GET",
        dataType: "JSON",
        success: function(data)
        {
            $('[name="id"]').val(data.id);
            $('[name="name"]').val(data.name);
            $('[name="url"]').val(data.url);
            $('[name = "category_id"]').val(data.category_id);
            $('[name = "description"]').val(data.description);

            if(data.photo !== null){
                $("#display-image").html("<img src="+data.photo+" style='width:40px;height:40px;object-fit:cover'>");
            }

            // Change form action to update URL
            $("form").attr("action", base_url + "administrator/partners/update");
            
            //load modal
            start_load()
            $("#partnerModal").modal('show');
            $(".modal-title").text("Edit Partner!");
            $(".sbtn").text("Update");
            setTimeout(function(){
            end_load();
        },500)
        }
    });
}
function delete_partner(id, name)
{
  var confirmation = confirm('Are you sure you want to delete ' + name + ' Partner?');
  if (confirmation) {
      window.location.href = base_url + '/administrator/partners/delete/' + id;
  }
}

/** =======================
 *  PARTNER CATEGORIES
 *===========================*/
function add_category(){
   $("#partnerCategoryModal").modal('show');
    start_load()
         
            $(".modal-title").text("Add Category");
            $(".sbtn").text("Save");
            setTimeout(function(){
            end_load();
    },500)
}

function edit_category(id)
{
    $("#partnerCategoryModal").modal('show');
    $.ajax({
        url:  base_url + 'administrator/partners/category/edit/'+ id,
        type: "GET",
        dataType: "JSON",
        success: function(data)
        {
            $('[name="id"]').val(data.id);
            $('[name="name"]').val(data.name);
            $('[name = "description"]').val(data.description);
            
            // Change form action to update URL
            $("form").attr("action", base_url + "administrator/partners/category/update");
            
            //load modal
            start_load()
            $("#partnerCategoryModal").modal('show');
            $(".modal-title").text("Edit Category!");
            $(".sbtn").text("Update");
            setTimeout(function(){
            end_load();
        },500)
        }
    });
}
function delete_category(id, name)
{
  var confirmation = confirm('Are you sure you want to delete ' + name + ' Category?');
  if (confirmation) {
      window.location.href = base_url + '/administrator/partners/category/delete/' + id;
  }
}