﻿//**********************************************************
// Journal DTOs
//----------------------------------------------------------
// Journals   
JournalDTO = Class.create();

JournalDTO.prototype = {
    initialize: function() {
        this.fieldSet = $A();
        this.dependencies = $A();
        this.behaviors = $A();

        this.fieldSet.push({ inputName: 'JournalID', dbName: 'JournalID', type: 'integer', key: true });
        this.fieldSet.push({ inputName: 'MemberID', dbName: 'MemberID', type: 'integer', key: true });
        this.fieldSet.push({ inputName: 'ValueCenterID', dbName: 'ValueCenterID', type: 'integer', key: true });
        this.fieldSet.push({ inputName: 'headline', dbName: 'Headline', type: 'string' });
        this.fieldSet.push({ inputName: 'body', dbName: 'Body', type: 'string' });
        this.fieldSet.push({ inputName: 'FullName', dbName: 'FullName', type: 'string' });
        this.fieldSet.push({ inputName: 'Date', dbName: 'Date', type: 'date' });
        this.fieldSet.push({ inputName: 'AvatarPath', dbName: 'AvatarPath', type: 'image', map: 'image' });
        this.fieldSet.push({ inputName: 'JournalLink', dbName: 'JournalID', type: 'int', map: 'linkTemplate', URLTemplate: '/#{JournalLink}#{JournalID}', clickModel: { mode: 'inplace', windowTitle: 'headline'} });        
    },


    FieldSet: function() { return this.fieldSet; },
    Dependencies: function() { return this.dependencies; },
    SelectMany: 'JournalsByAmbassadors'
}

//**********************************************************
// <!-- Page Configuration Scripts-->
//----------------------------------------------------------
Event.addBehavior({
    'body': function() {

        window.page = new $.page.HttpContext();

        _loadBlogPostControl();
    }
})

function _loadBlogPostControl() {
    // Instantiate a Query object
    // ...but the first configure the connector
    var proxy = '/Proxy.aspx';
    var serviceURL = 'http://localhost:8731/Design_Time_Addresses/ITTWatermark.WCFService/Service1/';

    var command = {
        queryVerb: 'SelectManyWithPost',
        parameters: {
            data: ''
        },
        type: 'QueryVerb' // could also be 'Stored Proc'
    };

    var controlFormat = {
        listType: 'pager',
        pageSize: 5,
        padding: '5px',
        pagerContainer: 'BlogPostPager',
        loadingImg: 'blog_loading',
        fieldPresentationRules:
        [
            { inputID: 'body', stripHTML: true, charSize: 200 },
            { inputID: 'AvatarPath', defaultPicture: '/images/avatar_NA.png', path: 'http://www.watermarkv3.itt.visionmix.com/Upload/#{UserName}/' },
            { inputID: 'headline', stripHTML: true, charSize: 47}
        ],
        recordsetPaging: 20
    };

    var controlParts = {
        container: 'BlogPost'
    };

    var journalQry = new $.data.Query(command, new JournalDTO(), new REST_WCF_DataConnector(proxy, serviceURL));

    var tableList = new $.ui.TableList(null, controlParts, null, controlFormat, journalQry, null);

    tableList._bind();
}
