##// END OF EJS Templates
Finishing first draft of RST and heading cells.
Finishing first draft of RST and heading cells.

File last commit:

r6003:617d1cb6
r6019:b6e93603
Show More
savewidget.js
179 lines | 5.4 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Minors fixes and initial work on save widget....
r4369
//============================================================================
Brian E. Granger
More review changes....
r4609 // SaveWidget
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 //============================================================================
var IPython = (function (IPython) {
var utils = IPython.utils;
var SaveWidget = function (selector) {
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 this.selector = selector;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.notebook_name_blacklist_re = /[\/\\]/;
Brian E. Granger
Fixing logic for rename behavior.
r4632 this.last_saved_name = '';
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 if (this.selector !== undefined) {
this.element = $(selector);
this.style();
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 this.bind_events();
}
};
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 SaveWidget.prototype.style = function () {
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#save_widget').addClass('ui-widget');
this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content');
Brian Granger
Improving the save notification....
r5874 this.element.find('span#save_status').addClass('ui-widget ui-widget-content')
.css({border: 'none', 'margin-left': '20px'});
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 };
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 SaveWidget.prototype.bind_events = function () {
var that = this;
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#notebook_name').click(function () {
that.rename_notebook();
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 });
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#notebook_name').hover(function () {
$(this).addClass("ui-state-hover");
}, function () {
$(this).removeClass("ui-state-hover");
Brian E. Granger
Save button becomes Rename when the notebook name changes.
r4630 });
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 };
Brian E. Granger
Adding keyboard shortcuts.
r4645 SaveWidget.prototype.save_notebook = function () {
IPython.notebook.save_notebook();
Felix Werner
Update document title and last_saved_name only after a successful save.
r5006 };
Brian Granger
Improved notebook renaming....
r5859 SaveWidget.prototype.rename_notebook = function () {
var that = this;
var dialog = $('<div/>');
dialog.append(
$('<h3/>').html('Enter a new notebook name:')
.css({'margin-bottom': '10px'})
);
dialog.append(
Brian Granger
More minor theme/styling changes.
r5871 $('<input/>').attr('type','text').attr('size','25')
Brian Granger
Solid first go at jquery-ui based menus.
r5869 .addClass('ui-widget ui-widget-content')
.attr('value',that.get_notebook_name())
Brian Granger
Improved notebook renaming....
r5859 );
Brian Granger
Remove Rename dialog from the DOM upon closing it.
r5872 // $(document).append(dialog);
Brian Granger
Improved notebook renaming....
r5859 dialog.dialog({
resizable: false,
modal: true,
title: "Rename Notebook",
closeText: "",
Brian Granger
Fixing bug in dialog closing, drafting print css.
r5873 close: function(event, ui) {$(this).dialog('destroy').remove();},
Brian Granger
Improved notebook renaming....
r5859 buttons : {
"OK": function () {
var new_name = $(this).find('input').attr('value');
if (!that.test_notebook_name(new_name)) {
$(this).find('h3').html(
Brian Granger
Disallow empty notebook names.
r5955 "Invalid notebook name. Notebook names must "+
"have 1 or more characters and can contain any characters " +
Brian Granger
Improved notebook renaming....
r5859 "except / and \\. Please enter a new notebook name:"
);
} else {
that.set_notebook_name(new_name);
that.save_notebook();
$(this).dialog('close');
}
},
"Cancel": function () {
$(this).dialog('close');
}
}
});
}
Felix Werner
Update document title and last_saved_name only after a successful save.
r5006 SaveWidget.prototype.notebook_saved = function () {
Brian E. Granger
Adding keyboard shortcuts.
r4645 this.set_document_title();
this.last_saved_name = this.get_notebook_name();
};
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 SaveWidget.prototype.get_notebook_name = function () {
Brian Granger
Improved notebook renaming....
r5859 return this.element.find('span#notebook_name').html();
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372
Brian E. Granger
Massive work on the notebook document format....
r4484 SaveWidget.prototype.set_notebook_name = function (nbname) {
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#notebook_name').html(nbname);
Brian E. Granger
Browser window title follows the name of the notebook.
r4549 this.set_document_title();
Brian E. Granger
Fixing logic for rename behavior.
r4632 this.last_saved_name = nbname;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372
Brian E. Granger
Minors fixes and initial work on save widget....
r4369
Brian E. Granger
Browser window title follows the name of the notebook.
r4549 SaveWidget.prototype.set_document_title = function () {
nbname = this.get_notebook_name();
Brian E. Granger
Misc changes to the notebook....
r5104 document.title = nbname;
Brian E. Granger
Browser window title follows the name of the notebook.
r4549 };
Brian E. Granger
Massive work on the notebook document format....
r4484 SaveWidget.prototype.get_notebook_id = function () {
Brian E. Granger
Adding base_project_url and base_kernel_url as HTML data attribs....
r5100 return $('body').data('notebookId');
Brian E. Granger
Massive work on the notebook document format....
r4484 };
SaveWidget.prototype.update_url = function () {
var notebook_id = this.get_notebook_id();
if (notebook_id !== '') {
Andrew Straw
bugfix: use baseProjectUrl when re-writing URL in address bar
r6003 var new_url = $('body').data('baseProjectUrl') + notebook_id;
Brian Granger
Finishing work on "Make a Copy" functionality.
r5861 window.history.replaceState({}, '', new_url);
Brian E. Granger
Massive work on the notebook document format....
r4484 };
};
Brian Granger
Improved notebook renaming....
r5859 SaveWidget.prototype.test_notebook_name = function (nbname) {
Brian Granger
Disallow empty notebook names.
r5955 nbname = nbname || '';
if (this.notebook_name_blacklist_re.test(nbname) == false && nbname.length>0) {
Brian E. Granger
Massive work on the notebook document format....
r4484 return true;
} else {
return false;
};
};
Brian Granger
Improving the save notification....
r5874 SaveWidget.prototype.set_last_saved = function () {
var d = new Date();
$('#save_status').html('Last saved: '+d.format('mmm dd h:MM TT'));
};
Felix Werner
Notify the user of errors when saving a notebook.
r5007 SaveWidget.prototype.reset_status = function () {
Brian Granger
Improving the save notification....
r5874 this.element.find('span#save_status').html('');
Felix Werner
Notify the user of errors when saving a notebook.
r5007 };
Brian Granger
Improving the save notification....
r5874 SaveWidget.prototype.status_last_saved = function () {
this.set_last_saved();
Stefan van der Walt
Implement static publishing of HTML notebook.
r4592 };
Brian E. Granger
Massive work on the notebook document format....
r4484
SaveWidget.prototype.status_saving = function () {
Brian Granger
Improving the save notification....
r5874 this.element.find('span#save_status').html('Saving...');
Stefan van der Walt
Implement static publishing of HTML notebook.
r4592 };
Brian E. Granger
Massive work on the notebook document format....
r4484
Brian Granger
Improving the save notification....
r5874 SaveWidget.prototype.status_save_failed = function () {
this.element.find('span#save_status').html('Save failed');
Brian Granger
Improved notebook renaming....
r5859 };
Brian E. Granger
Massive work on the notebook document format....
r4484
Brian Granger
Improving the save notification....
r5874 SaveWidget.prototype.status_loading = function () {
this.element.find('span#save_status').html('Loading...');
Brian E. Granger
Save button becomes Rename when the notebook name changes.
r4630 };
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 IPython.SaveWidget = SaveWidget;
return IPython;
}(IPython));