samedi 28 janvier 2017

Combine two Javascripts together

Can someone please help me combine these two scripts into one? I have no clue about javascript... I want to perform the same function on two different elements. Any help would be much appreciated. Thank you

{

(function() {

"use strict";
// Run an event when the record list page is displayed
kintone.events.on('app.record.index.show', function(event) {

    //Retrieve an array of field elements of the fields with field code of "Attendance"
    var elStatus = kintone.app.getFieldElements('Schstatus');

    //Change the properties of the retrieved field elements for each record
    for (var i = 0; i < elStatus.length; i++) 
    {
        var record = event.records[i];
        if (record['Schstatus']['value'] === "Call Out") 
        {
            elStatus[i].style.color = 'white';
            elStatus[i].style.backgroundColor = "#e74c3c";

        } 

        else if (record['Schstatus']['value'] === "Pending")
         {
            elStatus[i].style.color = 'black';
            elStatus[i].style.backgroundColor = "#ffcc00";
         }

         else if (record['Schstatus']['value'] === "Confirmed")
         {
            elStatus[i].style.color = 'white';
            elStatus[i].style.backgroundColor = "#a3b815";

         }

    }

});

})();

}

The second script is identical but with a different field....

{

(function() {

"use strict";
// Run an event when the record list page is displayed
kintone.events.on('app.record.index.show', function(event) {

    //Retrieve an array of field elements of the fields with field code of "Attendance"
    var elStatus = kintone.app.getFieldElements('Attendance');
    var elStatuss = kintone.app.getFieldElements('Schstatus');

    //Change the properties of the retrieved field elements for each record
    for (var i = 0; i < elStatus.length; i++) 
    {   var record = event.records[i];
        if (record['Attendance']['value'] === "No-Show") 

    {   elStatus[i].style.color = 'white';
        elStatus[i].style.backgroundColor = 'red';  } 


    else if (record['Attendance']['value'] === "Late")
    {   elStatus[i].style.color = "#a023bc";        }


    else if (record['Attendance']['value'] === "On-Time")
    {   elStatus[i].style.color = 'green';          }

    }

});

})();

}

Aucun commentaire:

Enregistrer un commentaire