/**
 * Returns a table row with the content in the transaction 
 * @returns json transaction
 * @type json
 */

function transactionGetJSON(trans) {
    var json = {
        id: trans.getId(),
        name: trans.getName(),
        amount: trans.getAmount(),
        date: trans.getDate(),
        description: trans.getDescription(),
        category: trans.getCategory(),
        dataString: trans.getDataString(),
        dataName: trans.getDataName(),
        user: trans.getUser()
    };
    return json;
}

/**
 * Returns a table row with the content in the transaction 
 * @returns A table row
 * @type html
 */

function transactionGetTableRow(trans, prefix) {

    var html = '<tr rel="' + prefix + '_' + trans.getId() + '"><td>' + trans.getName() + '</td><td>' + trans.getAmount() + '</td><td>' + trans.getDate() + '</td><td>' + trans.getDescription() + '</td><td>' + trans.getCategory() + '</td><td><a href="#" class="editTrans">Edit</a></td>';
    return html;
}

/**
 * Return a dropdown with categories
 * @param String Category chosen
 * @returns a dropdown with categories
 * @type html
 */
 /*
function getCategoriesDropDown(category) {
    var html = '<select name="category">';
    
    
    //SEEMS WEIRD!
    $(categories).each(function () {
        if (this.category === category) {
            html += '<option value="' + this.category + '" selected="selected">' + this.category + '</option>';
        } else {
            html += '<option value="' + this.category + '">' + this.category + '</option>';
        }
    });

    html += '</select>';
    return html;
}
*/
/**
 * Returns an table-edit row with the content in the transaction 
 * @returns A table row
 * @type html
 */

function transactionGetEditRow(trans) {
    var html = '<tr id="te_' + trans.getId() + '" class="editTE">';

    html += '<td><input type="text" name="name" value="' + trans.getName() + '"></td>';
    html += '<td><input type="text" name="amount" value="' + trans.getAmount() + '"></td>';
    html += '<td><input type="text" name="date" value="' + trans.getDate() + '"></td>';
    html += '<td><input type="text" name="description" value="' + trans.getDescription() + '"></td>';
    html += '<td>' + getCategoriesDropDown(trans.getCategory()) + '</td>';
    html += '<td><input type="button" name="update" class="update" value="Update"><input type="button" class="cancel" name="cancel" value="Cancel"></td>';
    html += '</tr>';

    return html;
}

/**
 * Return a dropdown with groups
 * @param String group chosen
 * @returns a dropdown with groups
 * @type html
 */

function getGroupsDropDown(group) {
    var html = '<select name="group">';


    // seems weird!
    $(groups).each(function () {
        if (this.name === group) {
            html += '<option value="' + this.name + '" selected="selected">' + this.name + '</option>';
        } else {
            html += '<option value="' + this.name + '">' + this.name + '</option>';
        }
    });

    html += '</select>';
    return html;
}


