<html>
<head>
<title>List Groups</title>
</head>
<!-- DataTables, TableTools and Editor CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.6/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/tabletools/2.2.4/css/dataTables.tableTools.css">
<link rel="stylesheet" type="text/css" href="STATIC/Editor-1.4.2/css/dataTables.editor.css">
  
<!-- jQuery, DataTables, TableTools and Editor Javascript -->
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.6/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/tabletools/2.2.4/js/dataTables.tableTools.js"></script>
<script type="text/javascript" src="STATIC/Editor-1.4.2/js/dataTables.editor.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script>
  <body>
    <br />
    <table id="table_id" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>ID</th>
            <th>EPIC</th>
            <th>STRATEGY</th>
            <th>BALANCE LV</th>
            <th>LOWEST LV</th>
            <th>HIGHEST LV</th>
            <th>CLOSE LV</th>
            <th>#CLOSED DEAL</th>  
            <th>#OPEN DEAL</th>  
            <th>#MAX OPEN DEAL</th>  
            <th>PROFIT</th>  
            <th>TYPE</th>  
            <th>EXPIRE</th>  
            <th>STATUS</th>  
            <th>CREATE DATETIME</th> 
            <th>MOD DATETIME</th> 
        </tr>
    </thead>
    <!--tbody>      
    <s:iterator value="list">
        <tr>
            <td><s:property value="marketID"/></td>
            <td><s:property value="position"/></td>
            <td><s:property value="action"/></td>
            <td><s:date name="issueDatetime"/></td>
            <td><s:property value="note"/></td>
        </tr>
    </s:iterator>
    </tbody-->
    </table>
</body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
div.container {
  min-width: 980px;
  margin: 0 auto;
}
 
// Todo field type plug-in code
(function ($, DataTable) {
 
if ( ! DataTable.ext.editorFields ) {
    DataTable.ext.editorFields = {};
}
 
var Editor = DataTable.Editor;
var _fieldTypes = DataTable.ext.editorFields;
 
_fieldTypes.todo = {
    create: function ( conf ) {
        var that = this;
 
        conf._enabled = true;
 
        // Create the elements to use for the input
        conf._input = $(
            '<div>'+
                '<button class="inputButton" value="0">To do</button>'+
                '<button class="inputButton" value="1">Done</button>'+
            '</div>')[0];
 
        // Use the fact that we are called in the Editor instance's scope to call
        // the API method for setting the value when needed
        $('button.inputButton', conf._input).click( function () {
            if ( conf._enabled ) {
                that.set( conf.name, $(this).attr('value') );
            }
 
            return false;
        } );
 
        return conf._input;
    },
 
    get: function ( conf ) {
        return $('button.selected', conf._input).attr('value');
    },
 
    set: function ( conf, val ) {
        $('button.selected', conf._input).removeClass( 'selected' );
        $('button.inputButton[value='+val+']', conf._input).addClass('selected');
    },
 
    enable: function ( conf ) {
        conf._enabled = true;
        $(conf._input).removeClass( 'disabled' );
    },
 
    disable: function ( conf ) {
        conf._enabled = false;
        $(conf._input).addClass( 'disabled' );
    }
};
 
})(jQuery, jQuery.fn.dataTable);
var editor, oTable;
$(document).ready( function () {
    editor = new $.fn.dataTable.Editor({
        ajax:  'group!execute',
        table: '#table_id',
        idSrc: "id",
        //display: 'envelope',
        fields: [
            { label: 'ID', name: 'id' },
            { label: 'EPIC', name: 'epic' }, //CAN'T BE NULL
            { label: 'STRATEGY ID',  name: 'strategyID', def: 0 },
            { label: 'BALANCE LEVEL',  name: 'balanceLevel', def: 0.0 },
            { label: 'LOWEST LEVEL',  name: 'lowestLevel', def: 0.0 },
            { label: 'HIGHEST LEVEL',  name: 'highestLevel', def: 0.0 },
            { label: 'CLOSE LEVEL',  name: 'closeLevel', def: 0.0 },
            { label: '#CLOSED DEAL',  name: 'noClosedDeal', def: 0 },
            { label: '#OPEN DEAL',  name: 'noOpenDeal', def: 0 },
            { label: '#MAX OPEN DEAL',  name: 'maxOpenDeal', def: 0 },
            { label: 'PROFIT',  name: 'profit', def: 0 },
         //    { label: 'PROFIT LOWEST LEVEL',  name: 'profitLowestLevel' },
            // { label: 'PROFIT HIGHEST LEVEL',  name: 'profitHighestLevel' },
            { label: 'TYPE',  name: 'type', def: 0 },
            { label: 'EXPIRE',  name: 'expire', type: 'hidden' },
            { label: 'STATUS',  name: 'status', def: 1 },
            { label: 'CREATE DATE',  name: 'createDatetime', type: 'hidden' },
            { label: 'MOD DATE',  name: 'modDatetime', type: 'hidden' }
            // etc
        ]
    }).disable('id');
    
    oTable = $('#table_id').dataTable({
        ajax: "group",
        dom: 'Tfrtip',
        iDisplayLength: 100,
        // columnDefs: [
        //     {
        //         "targets": [0],
        //         "visible": false,
        //         "searchable": false
        //     }
        // ],
        columns: [
            { "data": "id" },
            { "data": "epic" },
            { "data": "strategyID" },
            { "data": "balanceLevel" },
            { "data": "lowestLevel" },
            { "data": "highestLevel" },
            { "data": "closeLevel" },
            { "data": "noClosedDeal" },
            { "data": "noOpenDeal" },
            { "data": "maxOpenDeal" },
            { "data": "profit" },
            { "data": "type" },
            { "data": "expire" },
            { "data": "status" },
            { "data": "createDatetime" },
            { "data": "modDatetime" }
        ],
        tableTools: {
            sRowSelect: 'os',
            aButtons: [
                { sExtends: 'editor_create', editor: editor },
                { sExtends: 'editor_edit',   editor: editor },
                { sExtends: 'editor_remove', editor: editor },
                { //COPY Button
                    sExtends: 'select_single',
                    editor: editor,
                    sButtonClass: 'marginLeft',
                    sButtonText: 'Copy',
                    "fnClick": function (nButton, oConfig, oFlash) {
                            var oTT = TableTools.fnGetInstance( 'table_id' );
                            var aData = oTT.fnGetSelectedData();
                            var aSelectedTrs = oTT.fnGetSelected();
                            console.log(aData);
                            editor
                                .create()
                                .title( 'Add new by existing record' )
                                .set( 'epic', aData[0].epic )
                                .set( 'strategyID', aData[0].strategyID.length != 0 ? aData[0].strategyID : null )
                                .set( 'balanceLevel', aData[0].balanceLevel.length != 0 ? aData[0].balanceLevel : null )
                                .set( 'lowestLevel', aData[0].lowestLevel.length != 0 ? aData[0].lowestLevel : null  )
                                .set( 'highestLevel', aData[0].highestLevel.length != 0 ? aData[0].highestLevel : null )
                                .set( 'closeLevel', aData[0].closeLevel.length != 0 ? aData[0].closeLevel : null )
                                .set( 'noClosedDeal', aData[0].noClosedDeal.length != 0 ? aData[0].noClosedDeal : null )
                                .set( 'noOpenDeal', aData[0].noOpenDeal.length != 0 ? aData[0].noOpenDeal : null )
                                .set( 'maxOpenDeal', aData[0].maxOpenDeal.length != 0 ? aData[0].maxOpenDeal : null )
                                .set( 'profit', aData[0].profit.length != 0 ? aData[0].profit : null )
                                .set( 'type', aData[0].type.length != 0 ? aData[0].type : null )
                                // .set( 'expire', aData[0].dealID.length != 0 ? aData[0].dealID : null )
                                .set( 'status', aData[0].status.length != 0 ? aData[0].status : null )
                                .buttons( 'Create' ); 
                        return;
                    }
                },
                { //ANALYZE  TREAD Button
                    sExtends: 'select_single',
                    editor: editor,
                    sButtonClass: 'marginLeft',
                    sButtonText: 'Trend',
                    "fnClick": function (nButton, oConfig, oFlash) {
                        var oTT = TableTools.fnGetInstance( 'table_id' );
                        var aData = oTT.fnGetSelectedData();
                        var aSelectedTrs = oTT.fnGetSelected();
                        editor.add({
                                label: "Test:",
                                name: "test",
                                type: "todo", // Using the custom field type
                            });
                        
                        $.ajax({ //aJax get the balance level for a group
                            url: 'group!trend',
                            type: 'post',
                            data: 'id='+aData[0].id,
                            dataType: 'json',
                            cache: false,
                            error: function(){
                                alert("ALL THE DEALS UNDTER THE GROUP ARE CLOSED");
                                return;
                            },
                            success: function(json){
                                console.log(json);
                                editor.field('balanceLevel').val(json.balanceLv);
                                editor
                                    .title( 'Analyze Trend' )
                                    .buttons( 'Update' )
                                    .edit( aSelectedTrs[0] )
                                    .hide()
                                    .show('test')
                                    .show('balanceLevel');
                            },
                        });
                    }
                }
            ]
        }
    });
    
    var openVals;
    editor.on('preSubmit', function( e, data, action ) {
        console.log(action);
        console.log(data);
        if (action == 'create') {
            openVals = JSON.stringify( editor.get() );
            $.ajax({
                url: 'group!create',
                type: 'post',
                dataType: 'json',
                data: "gsonOperation="+openVals,
                cache: false,
                error: function(){
                    alert("ERROR");
                },
                success: function(json){ 
                    console.log("create success");
                } 
            });     
        } else if (action == 'edit') {
            openVals = JSON.stringify( editor.get() );
            $.ajax({
                url: 'group!update',
                type: 'post',
                dataType: 'json',
                data: "gsonOperation="+openVals,
                cache: false,
                error: function(){
                    console.log("ERROR");
                },
                success: function(json){ 
                    console.log("update success");
                } 
            });
        } else {
            console.log(JSON.stringify(data.id));
            $.ajax({
                url: 'group!delete',
                type: 'post',
                dataType: 'json',
                data: "gsonOperation="+JSON.stringify(data.id),
                cache: false,
                error: function(){
                    console.log("ERROR");
                },
                success: function(json){ 
                    console.log("delete success");
                } 
            });
        }
    });
    editor.on('preOpen', function( e ) {
        //When the form open, show all the field because the 'Trend' button make some field hidden
        editor.show().hide('createDatetime').hide('modDatetime');
    });
});
11 warnings
Line 138: Use '!==' to compare with '0'.
Line 139: Use '!==' to compare with '0'.
Line 140: Use '!==' to compare with '0'.
Line 141: Use '!==' to compare with '0'.
Line 142: Use '!==' to compare with '0'.
Line 143: Use '!==' to compare with '0'.
Line 144: Use '!==' to compare with '0'.
Line 145: Use '!==' to compare with '0'.
Line 146: Use '!==' to compare with '0'.
Line 147: Use '!==' to compare with '0'.
Line 149: Use '!==' to compare with '0'.
Output 300px

This bin was created anonymously and its free preview time has expired. Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers