Skip to content

Commit

Permalink
Merge pull request ipython#2897 from Carreau/baseurl-meth
Browse files Browse the repository at this point in the history
Dont rely on BaseProjectUrl data in body tag
  • Loading branch information
Carreau committed Feb 16, 2013
2 parents 98972ec + cd7593c commit 245c99b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 25 deletions.
10 changes: 7 additions & 3 deletions IPython/frontend/html/notebook/static/js/clusterlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var IPython = (function (IPython) {
}
};

ClusterList.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};

ClusterList.prototype.style = function () {
$('#cluster_toolbar').addClass('list_toolbar');
$('#cluster_list_info').addClass('toolbar_info');
Expand Down Expand Up @@ -52,7 +56,7 @@ var IPython = (function (IPython) {
dataType : "json",
success : $.proxy(this.load_list_success, this)
};
var url = $('body').data('baseProjectUrl') + 'clusters';
var url = this.baseProjectUrl() + 'clusters';
$.ajax(url, settings);
};

Expand Down Expand Up @@ -134,7 +138,7 @@ var IPython = (function (IPython) {
}
};
status_col.html('starting');
var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/start';
var url = this.baseProjectUrl() + 'clusters/' + that.data.profile + '/start';
$.ajax(url, settings);
};
});
Expand Down Expand Up @@ -168,7 +172,7 @@ var IPython = (function (IPython) {
}
};
status_col.html('stopping')
var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/stop';
var url = this.baseProjectUrl() + 'clusters/' + that.data.profile + '/stop';
$.ajax(url, settings);
});
};
Expand Down
9 changes: 5 additions & 4 deletions IPython/frontend/html/notebook/static/js/loginwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
//============================================================================

var IPython = (function (IPython) {
var base_url = $('body').data('baseProjectUrl');

var LoginWidget = function (selector) {
var LoginWidget = function (selector, options) {
var options = options || {};
this.base_url = options.baseProjectUrl || $('body').data('baseProjectUrl') ;
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
Expand All @@ -30,10 +31,10 @@ var IPython = (function (IPython) {
LoginWidget.prototype.bind_events = function () {
var that = this;
this.element.find("button#logout").click(function () {
window.location = base_url+"logout";
window.location = that.base_url+"logout";
});
this.element.find("button#login").click(function () {
window.location = base_url+"login";
window.location = that.base_url+"login";
});
};

Expand Down
41 changes: 35 additions & 6 deletions IPython/frontend/html/notebook/static/js/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,34 @@
// MenuBar
//============================================================================

/**
* @module IPython
* @namespace IPython
* @submodule MenuBar
*/


var IPython = (function (IPython) {

var MenuBar = function (selector) {
/**
* A MenuBar Class to generate the menubar of IPython noteboko
* @Class MenuBar
*
* @constructor
*
*
* @param selector {string} selector for the menubar element in DOM
* @param {object} [options]
* @param [options.baseProjectUrl] {String} String to use for the
* Base Project url, default would be to inspect
* $('body').data('baseProjectUrl');
* does not support change for now is set through this option
*/
var MenuBar = function (selector, options) {
var options = options || {};
if(options.baseProjectUrl!= undefined){
this._baseProjectUrl = options.baseProjectUrl;
}
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
Expand All @@ -20,6 +45,10 @@ var IPython = (function (IPython) {
}
};

MenuBar.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};


MenuBar.prototype.style = function () {
this.element.addClass('border-box-sizing');
Expand All @@ -37,17 +66,17 @@ var IPython = (function (IPython) {
MenuBar.prototype.bind_events = function () {
// File
this.element.find('#new_notebook').click(function () {
window.open($('body').data('baseProjectUrl')+'new');
window.open(this.baseProjectUrl()+'new');
});
this.element.find('#open_notebook').click(function () {
window.open($('body').data('baseProjectUrl'));
window.open(this.baseProjectUrl());
});
this.element.find('#rename_notebook').click(function () {
IPython.save_widget.rename_notebook();
});
this.element.find('#copy_notebook').click(function () {
var notebook_id = IPython.notebook.get_notebook_id();
var url = $('body').data('baseProjectUrl') + notebook_id + '/copy';
var url = this.baseProjectUrl() + notebook_id + '/copy';
window.open(url,'_blank');
return false;
});
Expand All @@ -56,13 +85,13 @@ var IPython = (function (IPython) {
});
this.element.find('#download_ipynb').click(function () {
var notebook_id = IPython.notebook.get_notebook_id();
var url = $('body').data('baseProjectUrl') + 'notebooks/' +
var url = this.baseProjectUrl() + 'notebooks/' +
notebook_id + '?format=json';
window.location.assign(url);
});
this.element.find('#download_py').click(function () {
var notebook_id = IPython.notebook.get_notebook_id();
var url = $('body').data('baseProjectUrl') + 'notebooks/' +
var url = this.baseProjectUrl() + 'notebooks/' +
notebook_id + '?format=py';
window.location.assign(url);
});
Expand Down
15 changes: 11 additions & 4 deletions IPython/frontend/html/notebook/static/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ var IPython = (function (IPython) {
var utils = IPython.utils;
var key = IPython.utils.keycodes;

var Notebook = function (selector) {
this.read_only = IPython.read_only;
var Notebook = function (selector, options) {
var options = options || {};
this._baseProjectUrl = options.baseProjectUrl;
this.read_only = options.read_only || IPython.read_only;

this.element = $(selector);
this.element.scroll();
this.element.data("notebook", this);
Expand Down Expand Up @@ -46,6 +49,10 @@ var IPython = (function (IPython) {
$('div#notebook').addClass('border-box-sizing');
};

Notebook.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};


Notebook.prototype.create_elements = function () {
// We add this end_space div to the end of the notebook div to:
Expand Down Expand Up @@ -1239,7 +1246,7 @@ var IPython = (function (IPython) {
error : $.proxy(this.save_notebook_error,this)
};
$([IPython.events]).trigger('notebook_saving.Notebook');
var url = $('body').data('baseProjectUrl') + 'notebooks/' + this.notebook_id;
var url = this.baseProjectUrl() + 'notebooks/' + this.notebook_id;
$.ajax(url, settings);
};

Expand Down Expand Up @@ -1268,7 +1275,7 @@ var IPython = (function (IPython) {
error : $.proxy(this.load_notebook_error,this),
};
$([IPython.events]).trigger('notebook_loading.Notebook');
var url = $('body').data('baseProjectUrl') + 'notebooks/' + this.notebook_id;
var url = this.baseProjectUrl() + 'notebooks/' + this.notebook_id;
$.ajax(url, settings);
};

Expand Down
14 changes: 9 additions & 5 deletions IPython/frontend/html/notebook/static/js/notebooklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var IPython = (function (IPython) {
}
};

NotebookList.prototype.baseProjectUrl = function () {
return $('body').data('baseProjectUrl')
};

NotebookList.prototype.style = function () {
$('#notebook_toolbar').addClass('list_toolbar');
$('#drag_info').addClass('toolbar_info');
Expand Down Expand Up @@ -100,7 +104,7 @@ var IPython = (function (IPython) {
},this)
};

var url = $('body').data('baseProjectUrl') + 'notebooks';
var url = this.baseProjectUrl() + 'notebooks';
$.ajax(url, settings);
};

Expand Down Expand Up @@ -162,7 +166,7 @@ var IPython = (function (IPython) {
var new_item_name = $('<span/>').addClass('item_name');
new_item_name.append(
$('<a/>').
attr('href', $('body').data('baseProjectUrl')+notebook_id).
attr('href', this.baseProjectUrl()+notebook_id).
attr('target','_blank').
text(nbname)
);
Expand Down Expand Up @@ -212,7 +216,7 @@ var IPython = (function (IPython) {
that.load_list();
}
};
var url = $('body').data('baseProjectUrl') + 'kernels/'+kernel;
var url = this.baseProjectUrl() + 'kernels/'+kernel;
$.ajax(url, settings);
});
new_buttons.append(shutdown_button);
Expand Down Expand Up @@ -253,7 +257,7 @@ var IPython = (function (IPython) {
parent_item.remove();
}
};
var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id;
var url = this.baseProjectUrl() + 'notebooks/' + notebook_id;
$.ajax(url, settings);
$(this).dialog('close');
},
Expand Down Expand Up @@ -302,7 +306,7 @@ var IPython = (function (IPython) {
};

var qs = $.param({name:nbname, format:nbformat});
var url = $('body').data('baseProjectUrl') + 'notebooks?' + qs;
var url = this.baseProjectUrl() + 'notebooks?' + qs;
$.ajax(url, settings);
});
var cancel_button = $('<button>Cancel</button>').button().
Expand Down
8 changes: 5 additions & 3 deletions IPython/frontend/html/notebook/static/js/notebookmain.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ $(document).ready(function () {
// The header's bottom border is provided by the menu bar so we remove it.
$('div#header').css('border-bottom-style','none');

var baseProjectUrl = $('body').data('baseProjectUrl')

IPython.page = new IPython.Page();
IPython.markdown_converter = new Markdown.Converter();
IPython.layout_manager = new IPython.LayoutManager();
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.quick_help = new IPython.QuickHelp('span#quick_help_area');
IPython.login_widget = new IPython.LoginWidget('span#login_widget');
IPython.notebook = new IPython.Notebook('div#notebook');
IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl});
IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only});
IPython.save_widget = new IPython.SaveWidget('span#save_widget');
IPython.menubar = new IPython.MenuBar('#menubar')
IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl})
IPython.toolbar = new IPython.MainToolBar('#maintoolbar')
IPython.tooltip = new IPython.Tooltip()
IPython.notification_area = new IPython.NotificationArea('#notification_area')
Expand Down

0 comments on commit 245c99b

Please sign in to comment.