﻿//**********************************************************
// RSSFeed DTO
//----------------------------------------------------------

RSSFeedDTO = Class.create();

Object.extend(RSSFeedDTO.prototype, {
    initialize: function() {
        this.fieldSet = $A();

        this.fieldSet.push({ inputName: 'RSSPublisher', dbName: 'RSSPublisher', type: 'string' });
        this.fieldSet.push({ inputName: 'RSSTitle', dbName: 'RSSTitle', type: 'string' });
        this.fieldSet.push({ inputName: 'RSSDescription', dbName: 'RSSDescription', type: 'string' });
        this.fieldSet.push({ inputName: 'RSSPubDate', dbName: 'RSSPubDate', type: 'string' });
        this.fieldSet.push({ inputName: 'RSSLink', dbName: 'RSSLink', type: 'link' });
        this.fieldSet.push({ inputName: 'RSSLapsedTime', dbName: 'RSSLapsedTime', type: 'string' });
    },

    FieldSet: function() { return this.fieldSet; },
    Dependencies: function() { return this.dependencies; },
    SelectMany: 'TweeterRSSFeed/{URL}'
    // SelectMany: 'http://twitter.com/statuses/user_timeline/16688755.rss'
});

//**********************************************************
// Notes DTO
//----------------------------------------------------------
NoteDTO = Class.create();

Object.extend(NoteDTO.prototype, {
    initialize: function() {
        this.fieldSet = $A();

        this.fieldSet.push({ inputName: 'NoteID', dbName: 'NoteID', type: 'int' });
        this.fieldSet.push({ inputName: 'TripID', dbName: 'TripID', type: 'int' });
        this.fieldSet.push({ inputName: 'MemberID', dbName: 'MemberID', type: 'string' });
        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: 'string' });
        this.fieldSet.push({ inputName: 'AvatarPath', dbName: 'AvatarPath', type: 'image', map:'image' });
        this.fieldSet.push({ inputName: 'NoteLink', dbName: 'NoteID', type: 'int', map: 'linkTemplate', URLTemplate: '/#{NoteLink}#{NoteID}', clickModel: { mode: 'popup', windowTitle: 'headline'} });        
    },

//    SelectMany: 'NotesList'
      //SelectMany: 'JournalsListV2'
      SelectMany: 'NotesListV2'

});

//**********************************************************
// 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' });
        this.fieldSet.push({ inputName: 'JournalLink', dbName: 'Link', type: 'link' });
    },


    FieldSet: function() { return this.fieldSet; },
    Dependencies: function() { return this.dependencies; },
    SelectMany: 'JournalsList'
}


//**********************************************************
// <!-- Page Configuration Scripts-->
//----------------------------------------------------------
window.onload = function() {
    window.page = new $.page.HttpContext();
    _loadDefaultPage();
}

function _loadDefaultPage() {
    _loadRSSVonEulerFeed();
    _loadRSSFeed();
    _loadBlogPostControl();
}

function _loadRSSVonEulerFeed() {
    // Instantiate a Query object
    // ...but the first configure the connector
    var proxy = '/Proxy.aspx';

    //var feeds = [{ URL: 'http://twitter.com/statuses/friends_timeline/24750535.rss', UserID: 'jwilson@coneinc.com', Password: 'water123' }];

    var feeds = [{ URL: 'http://twitter.com/statuses/user_timeline/24750535.rss'}];


    var command = {
        queryVerb: 'SelectManyWithPost',
        parameters: {
            data: feeds
        },
        type: 'QueryVerb' // could also be 'Stored Proc'
    };

    var controlFormat = {
        listType: 'xact-count',
        padding: '5px',
        pageSize: 1,
        pagerContainer: 'vonEulerPager',
        loadingImg: 'vonEuler_loading',
        fieldPresentationRules:
        [
            { inputID: 'RSSDescription', stripHTML: false }
        ],
        recordsetPaging: 15
    };

    var controlParts = {
        container: 'TweetFeedITEM'
    };

    var tweeterRSSQry = new $.data.Query(command, new RSSFeedDTO(), new REST_WCF_DataConnector(proxy, null));
    
    var rssReader = new $.ui.TableList(null, controlParts, null, controlFormat, tweeterRSSQry, null);

    rssReader._bind();
}

function _loadRSSFeed() {
    // 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 feeds = [{ URL: 'http://twitter.com/statuses/user_timeline/16688755.rss' },
                  { URL: 'http://feeds.feedburner.com/waterforpeopleblog'}];

    var command = {
        queryVerb: 'SelectManyWithPost',
        parameters: {
            data: feeds
        },
        type: 'QueryVerb' // could also be 'Stored Proc'
    };

    var controlFormat = {
        listType: 'pager',
        padding: '5px',
        pageSize: 3,
        pagerContainer: 'RSSFeedPager',
        loadingImg: 'rss_loading',
        fieldPresentationRules:
        [
            { inputID: 'RSSDescription', stripHTML: false, charSize: 200 }
        ],
        recordsetPaging: 15
    };

    var controlParts = {
        container: 'RSSItem'
    };

    var tweeterRSSQry = new $.data.Query(command, new RSSFeedDTO(), new REST_WCF_DataConnector(proxy, serviceURL));

    var rssReader = new $.ui.TableList(null, controlParts, null, controlFormat, tweeterRSSQry, null);

    rssReader._bind();
}

function _loadBlogPostControl(journalTable, tripID) {
    // 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,
        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: 60 }
        ],
        recordsetPaging: 20
    };

    var controlParts = {
        container: 'BlogPost'
    };

    var noteQry = new $.data.Query(command, new NoteDTO(), new REST_WCF_DataConnector(proxy, serviceURL));

    var tableList = new $.ui.TableList(null, controlParts, null, controlFormat, noteQry, null);

    tableList._bind();
}
