##// END OF EJS Templates
disable install from master...
disable install from master while it's broken by The Big Split with informative note about `pip install -e`

File last commit:

r19502:337a994f
r21036:5b38bd7e
Show More
savewidget.js
225 lines | 7.9 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Almost done!...
r17198 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Almost done!...
r17198 'base/js/utils',
'base/js/dialog',
'base/js/keyboard',
Matthias BUSSONNIER
use momentjs for nice dates
r17474 'moment',
], function(IPython, $, utils, dialog, keyboard, moment) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
Brian E. Granger
Minors fixes and initial work on save widget....
r4369
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 var SaveWidget = function (selector, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* TODO: Remove circular ref.
*/
Jonathan Frederic
Almost done!...
r17198 this.notebook = undefined;
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 this.selector = selector;
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 this.events = options.events;
Matthias BUSSONNIER
use momentjs for nice dates
r17474 this._checkpoint_date = undefined;
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 this.keyboard_manager = options.keyboard_manager;
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 if (this.selector !== undefined) {
this.element = $(selector);
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
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 SaveWidget.prototype.bind_events = function () {
var that = this;
Min RK
make savewidget css a little more generic...
r19315 this.element.find('span.filename').click(function () {
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 that.rename_notebook({notebook: that.notebook});
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 });
Jonathan Frederic
Almost done!...
r17198 this.events.on('notebook_loaded.Notebook', function () {
Brian Granger
Major refactoring of saving, notification....
r6047 that.update_notebook_name();
that.update_document_title();
});
Jonathan Frederic
Almost done!...
r17198 this.events.on('notebook_saved.Notebook', function () {
Brian Granger
Major refactoring of saving, notification....
r6047 that.update_notebook_name();
that.update_document_title();
});
Jonathan Frederic
Almost done!...
r17198 this.events.on('notebook_renamed.Notebook', function () {
Zachary Sailer
allow spaces in notebook path
r13012 that.update_notebook_name();
that.update_document_title();
Zachary Sailer
redirect url after notebook rename
r13010 that.update_address_bar();
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 });
Jonathan Frederic
Almost done!...
r17198 this.events.on('notebook_save_failed.Notebook', function () {
MinRK
use dirty event to set autosaved/unsaved changes...
r10829 that.set_save_status('Autosave Failed!');
Brian Granger
Major refactoring of saving, notification....
r6047 });
Min RK
handle various permission failures...
r19005 this.events.on('notebook_read_only.Notebook', function () {
that.set_save_status('(read only)');
// disable future set_save_status
that.set_save_status = function () {};
});
Jonathan Frederic
Almost done!...
r17198 this.events.on('checkpoints_listed.Notebook', function (event, data) {
Matthias BUSSONNIER
use momentjs for nice dates
r17474 that._set_last_checkpoint(data[0]);
MinRK
add checkpoint status to notebook header...
r10516 });
Kevin Burke
Select default title when renaming a notebook...
r12368
Jonathan Frederic
Almost done!...
r17198 this.events.on('checkpoint_created.Notebook', function (event, data) {
Matthias BUSSONNIER
use momentjs for nice dates
r17474 that._set_last_checkpoint(data);
MinRK
add checkpoint status to notebook header...
r10516 });
Jonathan Frederic
Almost done!...
r17198 this.events.on('set_dirty.Notebook', function (event, data) {
MinRK
use dirty event to set autosaved/unsaved changes...
r10829 that.set_autosaved(data.value);
});
Felix Werner
Update document title and last_saved_name only after a successful save.
r5006 };
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 SaveWidget.prototype.rename_notebook = function (options) {
options = options || {};
Brian Granger
Improved notebook renaming....
r5859 var that = this;
Jonathan Frederic
Fix all the bugs!
r17203 var dialog_body = $('<div/>').append(
MinRK
add break between prompt and input in Rename dialog
r10956 $("<p/>").addClass("rename-message")
Matthias BUSSONNIER
some $.html( -> $.text(...
r14634 .text('Enter a new notebook name:')
MinRK
add break between prompt and input in Rename dialog
r10956 ).append(
$("<br/>")
).append(
Jonathan Frederic
Review comments
r16957 $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 .val(options.notebook.get_notebook_name())
Brian Granger
Improved notebook renaming....
r5859 );
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 var d = dialog.modal({
Brian Granger
Improved notebook renaming....
r5859 title: "Rename Notebook",
Jonathan Frederic
Fix all the bugs!
r17203 body: dialog_body,
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 notebook: options.notebook,
keyboard_manager: this.keyboard_manager,
Brian Granger
Improved notebook renaming....
r5859 buttons : {
MinRK
bootstrap dialogs
r10895 "OK": {
class: "btn-primary",
click: function () {
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 var new_name = d.find('input').val();
if (!options.notebook.test_notebook_name(new_name)) {
d.find('.rename-message').text(
"Invalid notebook name. Notebook names must "+
"have 1 or more characters and can contain any characters " +
"except :/\\. Please enter a new notebook name:"
);
return false;
} else {
d.find('.rename-message').text("Renaming...");
d.find('input[type="text"]').prop('disabled', true);
that.notebook.rename(new_name).then(
function () {
d.modal('hide');
}, function (error) {
d.find('.rename-message').text(error.message || 'Unknown error');
d.find('input[type="text"]').prop('disabled', false).focus().select();
}
);
return false;
}
Brian Granger
Improved notebook renaming....
r5859 }
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 },
David Neto
Change the order of Cancel and OK button in the renaming function so it matches the user experience for the same dialog boxes used in the main dashboard
r18926 "Cancel": {}
Brian Granger
Improved notebook renaming....
r5859 },
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 open : function () {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Upon ENTER, click the OK button.
*/
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 d.find('input[type="text"]').keydown(function (event) {
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 if (event.which === keyboard.keycodes.enter) {
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 d.find('.btn-primary').first().click();
MinRK
swallow enter event in rename dialog...
r12019 return false;
Brian Granger
ENTER submits the rename notebook dialog.
r7246 }
});
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 d.find('input[type="text"]').focus().select();
Brian Granger
Improved notebook renaming....
r5859 }
});
Jonathan Frederic
Almost done!...
r17198 };
Brian Granger
Improved notebook renaming....
r5859
Brian E. Granger
Adding keyboard shortcuts.
r4645
Brian Granger
Major refactoring of saving, notification....
r6047 SaveWidget.prototype.update_notebook_name = function () {
Jonathan Frederic
Almost done!...
r17198 var nbname = this.notebook.get_notebook_name();
Min RK
make savewidget css a little more generic...
r19315 this.element.find('span.filename').text(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 Granger
Major refactoring of saving, notification....
r6047 SaveWidget.prototype.update_document_title = function () {
Jonathan Frederic
Almost done!...
r17198 var nbname = this.notebook.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 };
Matthias BUSSONNIER
use momentjs for nice dates
r17474
Zachary Sailer
redirect url after notebook rename
r13010 SaveWidget.prototype.update_address_bar = function(){
Jonathan Frederic
Almost done!...
r17198 var base_url = this.notebook.base_url;
var path = this.notebook.notebook_path;
Min RK
update frontend with path/name changes...
r18752 var state = {path : path};
MinRK
make sure to encode URL components for API requests...
r13693 window.history.replaceState(state, "", utils.url_join_encode(
MinRK
don't forget base_url when updating address bar in rename
r15483 base_url,
"notebooks",
Min RK
update frontend with path/name changes...
r18752 path)
MinRK
review pass on multidir js
r13103 );
MinRK
don't forget base_url when updating address bar in rename
r15483 };
Brian E. Granger
Massive work on the notebook document format....
r4484
Brian Granger
Major refactoring of saving, notification....
r6047 SaveWidget.prototype.set_save_status = function (msg) {
Min RK
make savewidget css a little more generic...
r19315 this.element.find('span.autosave_status').text(msg);
Jonathan Frederic
Almost done!...
r17198 };
MinRK
add checkpoint status to notebook header...
r10516
Min RK
fix regular checkpoint updates in notebook...
r19502 SaveWidget.prototype._set_last_checkpoint = function (checkpoint) {
if (checkpoint) {
this._checkpoint_date = new Date(checkpoint.last_modified);
Matthias BUSSONNIER
use momentjs for nice dates
r17474 } else {
Min RK
fix regular checkpoint updates in notebook...
r19502 this._checkpoint_date = null;
Matthias BUSSONNIER
use momentjs for nice dates
r17474 }
Min RK
fix regular checkpoint updates in notebook...
r19502 this._render_checkpoint();
MinRK
fix handling of no-checkpoint-defined...
r17715 };
Min RK
fix regular checkpoint updates in notebook...
r19502
SaveWidget.prototype._render_checkpoint = function () {
/** actually set the text in the element, from our _checkpoint value
called directly, and periodically in timeouts.
*/
this._schedule_render_checkpoint();
var el = this.element.find('span.checkpoint_status');
if (!this._checkpoint_date) {
el.text('').attr('title', 'no checkpoint');
MinRK
add missing return...
r10547 return;
MinRK
fix set_last_checkpoint when no checkpoint...
r10532 }
Matthias BUSSONNIER
use momentjs for nice dates
r17474 var chkd = moment(this._checkpoint_date);
Min RK
fix regular checkpoint updates in notebook...
r19502 var long_date = chkd.format('llll');
var human_date;
var tdelta = Math.ceil(new Date() - this._checkpoint_date);
if (tdelta < utils.time.milliseconds.d){
// less than 24 hours old, use relative date
human_date = chkd.fromNow();
} else {
// otherwise show calendar
// <Today | yesterday|...> at hh,mm,ss
human_date = chkd.calendar();
Matthias BUSSONNIER
use momentjs for nice dates
r17474 }
Min RK
fix regular checkpoint updates in notebook...
r19502 el.text('Last Checkpoint: ' + human_date).attr('title', long_date);
MinRK
fix handling of no-checkpoint-defined...
r17715 };
Matthias BUSSONNIER
use momentjs for nice dates
r17474
Min RK
fix regular checkpoint updates in notebook...
r19502
SaveWidget.prototype._schedule_render_checkpoint = function () {
/** schedule the next update to relative date
periodically updated, so short values like 'a few seconds ago' don't get stale.
*/
if (!this._checkpoint_date) {
return;
MinRK
fix handling of no-checkpoint-defined...
r17715 }
Min RK
fix regular checkpoint updates in notebook...
r19502 if ((this._checkpoint_timeout)) {
clearTimeout(this._checkpoint_timeout);
}
var dt = Math.ceil(new Date() - this._checkpoint_date);
this._checkpoint_timeout = setTimeout(
$.proxy(this._render_checkpoint, this),
utils.time.timeout_from_dt(dt)
);
Jonathan Frederic
Almost done!...
r17198 };
Brian E. Granger
Massive work on the notebook document format....
r4484
MinRK
use dirty event to set autosaved/unsaved changes...
r10829 SaveWidget.prototype.set_autosaved = function (dirty) {
if (dirty) {
this.set_save_status("(unsaved changes)");
} else {
this.set_save_status("(autosaved)");
}
Brian E. Granger
Save button becomes Rename when the notebook name changes.
r4630 };
Matthias BUSSONNIER
use dataformat module explicitely
r17443 // Backwards compatibility.
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 IPython.SaveWidget = SaveWidget;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'SaveWidget': SaveWidget};
Brian E. Granger
Minors fixes and initial work on save widget....
r4369
Jonathan Frederic
Almost done!...
r17198 });