##// END OF EJS Templates
Dont prompt for name.
Jonathan Frederic -
Show More
@@ -72,18 +72,12 b' define(['
72 if (!NotebookList._bound_singletons) {
72 if (!NotebookList._bound_singletons) {
73 NotebookList._bound_singletons = true;
73 NotebookList._bound_singletons = true;
74 $('#new-file').click(function(e) {
74 $('#new-file').click(function(e) {
75 that._prompt_name('File').then(function(name) {
75 that.contents.new_untitled(that.notebook_path || '', {type: 'file', ext: '.txt'});
76 that._create('file', name).then(function() {
76 that.load_sessions();
77 that.load_sessions();
78 });
79 });
80 });
77 });
81 $('#new-folder').click(function(e) {
78 $('#new-folder').click(function(e) {
82 that._prompt_name('Folder').then(function(name) {
79 that.contents.new_untitled(that.notebook_path || '', {type: 'directory'});
83 that._create('directory', name).then(function() {
80 that.load_sessions();
84 that.load_sessions();
85 });
86 });
87 });
81 });
88 }
82 }
89 };
83 };
@@ -538,90 +532,6 b' define(['
538 .append(cancel_button);
532 .append(cancel_button);
539 };
533 };
540
534
541 /**
542 * Prompt the user for a name.
543 * @param {string} what - What you want a name for.
544 * @return {Promise} Promise that resolve with a string name
545 */
546 NotebookList.prototype._prompt_name = function(what) {
547 var that = this;
548 var dialog_body = $('<div/>').append(
549 $("<p/>").addClass("rename-message")
550 .text(what + ' name:')
551 ).append(
552 $("<br/>")
553 ).append(
554 $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
555 .val('') // Default to empty
556 );
557
558 return new Promise(function(resolve, reject) {
559 var dialog_inst = dialog.modal({
560 title: "Rename Notebook",
561 body: dialog_body,
562 buttons: {
563 "OK": {
564 class: "btn-primary",
565 click: function () {
566 resolve(dialog_inst.find('input').val());
567 }
568 },
569 "Cancel": {
570 click: function () {
571 reject();
572 }
573 }
574 }, open: function () {
575 /**
576 * Upon ENTER, click the OK button.
577 */
578 dialog_inst.find('input[type="text"]').keydown(function (event) {
579 if (event.which === keyboard.keycodes.enter) {
580 dialog_inst.find('.btn-primary').first().click();
581 return false;
582 }
583 });
584 dialog_inst.find('input[type="text"]').focus().select();
585 }
586 });
587 });
588 };
589
590 /**
591 * Creates a `file` or `directory`
592 * @param {string} type - "file" or "directory"
593 * @param {string} name - name of the thing to create
594 * @return {Promise} success
595 */
596 NotebookList.prototype._create = function(type, name) {
597 var that = this;
598 return new Promise(function(resolve, reject) {
599 var settings = {
600 processData : false,
601 cache : false,
602 type : "PUT",
603 data: JSON.stringify({
604 type: type,
605 format: 'text',
606 content: '',
607 }),
608 dataType: "json",
609 success: function () {
610 resolve();
611 },
612 error: function() {
613 reject();
614 utils.log_ajax_error.apply(this, arguments);
615 },
616 };
617 var url = utils.url_join_encode(
618 that.base_url,
619 'api/contents/' + name
620 );
621 $.ajax(url, settings);
622 });
623 };
624
625
535
626 // Backwards compatability.
536 // Backwards compatability.
627 IPython.NotebookList = NotebookList;
537 IPython.NotebookList = NotebookList;
General Comments 0
You need to be logged in to leave comments. Login now