/**
 * Initialization code for the dashboard pages.
 */

'use strict';

var Raven = require('raven-js');
var ko = require('knockout');
var $ = require('jquery');
var jstz = require('jstimezonedetect').jstz;

var $osf = require('js/osfHelpers');
var FileBrowser = require('js/file-browser.js');
var LogFeed = require('js/logFeed');
var ProjectOrganizer = require('js/projectorganizer').ProjectOrganizer;
var m = require('mithril'); // exposes mithril methods, useful for redraw etc.

var url = '/api/v1/dashboard/get_nodes/';
var request = $.getJSON(url, function(response) {
    var allNodes = response.nodes;
    //.. Getting nodes
});
request.fail(function(xhr, textStatus, error) {
    Raven.captureMessage('Could not fetch dashboard nodes.', {
        url: url, textStatus: textStatus, error: error
    });
});

var nodesListUrl = '/api/v1/dashboard/get_nodes/';

var ensureUserTimezone = function(savedTimezone, savedLocale, id) {
    var clientTimezone = jstz.determine().name();
    var clientLocale = window.navigator.userLanguage || window.navigator.language;

    if (savedTimezone !== clientTimezone || savedLocale !== clientLocale) {
        var url = '/api/v1/profile/';

        var request = $osf.putJSON(
            url,
            {
                'timezone': clientTimezone,
                'locale': clientLocale,
                'id': id
            }
        );
        request.fail(function(xhr, textStatus, error) {
            Raven.captureMessage('Could not set user timezone or locale', {
                url: url,
                textStatus: textStatus,
                error: error
            });
        });
    }
};

$(document).ready(function() {
    $('#projectOrganizerScope').tooltip({selector: '[data-toggle=tooltip]'});

    var Fetch = {
        controller : function(){
            this.data = m.prop('');
            m.request({method: 'GET', url: '/api/v1/dashboard/'}).then(this.data);
        },
        view : function (ctrl){
            if (ctrl.data()){
                return m('', m.component(FileBrowser, { data : ctrl.data().data }));
            }
            return m('');
        }
    };
    m.mount(document.getElementById('fileBrowser'), Fetch );

    //    ensureUserTimezone(result.timezone, result.locale, result.id);
    //
    //request.fail(function(xhr, textStatus, error) {
    //    Raven.captureMessage('Failed to populate user dashboard', {
    //        url: url,
    //        textStatus: textStatus,
    //        error: error
    //    });
    //});

});


@@ -1753,25 +1753,24 @@
 ip%5D'%7D);%0A
-%0A
     var 
 Fetch = 
@@ -1765,385 +1765,233 @@
 var 
-Fetch = %7B%0A        controller : function()%7B%0A            this.data = m.prop('');%0A            m.request(%7Bmethod: 'GET', url: '/api/v1/dashboard/'%7D).then(this.data);%0A        %7D,%0A        view : function (ctrl)%7B%0A            if (ctrl.data())%7B%0A                return m('', m.component(FileBrowser, %7B data : ctrl.data().data %7D));%0A            %7D%0A            return m('');%0A        %7D
+request = $.ajax(%7B%0A        url:  'http://localhost:8000/v2/users/me/nodes',%0A        crossOrigin: true,%0A        xhrFields: %7B withCredentials: true%7D%0A    %7D);%0A    request.done(function(result) %7B%0A        console.log(result);%0A
 %0A    
-%7D;%0A
     
@@ -2042,28 +2042,69 @@
 '), 
-Fetch );%0A
+m.component(FileBrowser, %7B data : result.data%7D ));
 %0A    
-//
     
+//
 ensu
@@ -2170,17 +2170,16 @@
     
-//
+%7D);
 %0A    
-//
 requ
@@ -2222,26 +2222,24 @@
 rror) %7B%0A    
-//
     Raven.ca
@@ -2290,26 +2290,24 @@
 ard', %7B%0A    
-//
         url:
@@ -2312,26 +2312,24 @@
 l: url,%0A    
-//
         text
@@ -2348,26 +2348,24 @@
 Status,%0A    
-//
         erro
@@ -2377,18 +2377,16 @@
 ror%0A    
-//
     %7D);%0A
@@ -2389,18 +2389,16 @@
 %7D);%0A    
-//
 %7D);%0A%0A%7D);

Convert ajax request to v2 api