##// END OF EJS Templates
Don't do UI stuff in contents API module
Thomas Kluyver -
Show More
@@ -68,39 +68,20 define([
68 * @method scroll_to_cell
68 * @method scroll_to_cell
69 * @param {String} path The path to create the new notebook at
69 * @param {String} path The path to create the new notebook at
70 */
70 */
71 Contents.prototype.new_notebook = function(path) {
71 Contents.prototype.new_notebook = function(path, options) {
72 var base_url = this.base_url;
72 var base_url = this.base_url;
73 var success_callback = options.success_callback || function(data, status, xhr) {};
74 var error_callback = options.error_callback || function(xhr, status, error) {};
73 var settings = {
75 var settings = {
74 processData : false,
76 processData : false,
75 cache : false,
77 cache : false,
76 type : "POST",
78 type : "POST",
77 dataType : "json",
79 dataType : "json",
78 async : false,
80 async : false,
79 success : function (data, status, xhr){
81 success : success_callback,
80 var notebook_name = data.name;
81 window.open(
82 utils.url_join_encode(
83 base_url,
84 'notebooks',
85 path,
86 notebook_name
87 ),
88 '_blank'
89 );
90 },
91 error : function(xhr, status, error) {
82 error : function(xhr, status, error) {
92 utils.log_ajax_error(xhr, status, error);
83 utils.log_ajax_error(xhr, status, error);
93 var msg;
84 error_callback(xhr, status, error);
94 if (xhr.responseJSON && xhr.responseJSON.message) {
95 msg = xhr.responseJSON.message;
96 } else {
97 msg = xhr.statusText;
98 }
99 dialog.modal({
100 title : 'Creating Notebook Failed',
101 body : "The error was: " + msg,
102 buttons : {'OK' : {'class' : 'btn-primary'}}
103 });
104 }
85 }
105 };
86 };
106 var url = utils.url_join_encode(
87 var url = utils.url_join_encode(
@@ -89,7 +89,29 define([
89 this.element.find('#new_notebook').click(function () {
89 this.element.find('#new_notebook').click(function () {
90 // Create a new notebook in the same path as the current
90 // Create a new notebook in the same path as the current
91 // notebook's path.
91 // notebook's path.
92 that.contents.new_notebook(that.notebook.notebook_path);
92 that.contents.new_notebook(that.notebook.notebook_path,
93 {
94 success_callback: function (data, status, xhr) {
95 window.open(
96 utils.url_join_encode(
97 common_options.base_url, 'notebooks',
98 data.path, data.name
99 ), '_blank');
100 },
101 error_callback: function(xhr, status, error) {
102 var msg;
103 if (xhr.responseJSON && xhr.responseJSON.message) {
104 msg = xhr.responseJSON.message;
105 } else {
106 msg = xhr.statusText;
107 }
108 dialog.modal({
109 title : 'Creating Notebook Failed',
110 body : "The error was: " + msg,
111 buttons : {'OK' : {'class' : 'btn-primary'}}
112 });
113 }
114 });
93 });
115 });
94 this.element.find('#open_notebook').click(function () {
116 this.element.find('#open_notebook').click(function () {
95 window.open(utils.url_join_encode(
117 window.open(utils.url_join_encode(
@@ -60,7 +60,29 require([
60 login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
60 login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
61
61
62 $('#new_notebook').button().click(function (e) {
62 $('#new_notebook').button().click(function (e) {
63 contents.new_notebook(common_options.notebook_path);
63 contents.new_notebook(common_options.notebook_path,
64 {
65 success_callback: function (data, status, xhr) {
66 window.open(
67 utils.url_join_encode(
68 common_options.base_url, 'notebooks',
69 data.path, data.name
70 ), '_blank');
71 },
72 error_callback: function(xhr, status, error) {
73 var msg;
74 if (xhr.responseJSON && xhr.responseJSON.message) {
75 msg = xhr.responseJSON.message;
76 } else {
77 msg = xhr.statusText;
78 }
79 dialog.modal({
80 title : 'Creating Notebook Failed',
81 body : "The error was: " + msg,
82 buttons : {'OK' : {'class' : 'btn-primary'}}
83 });
84 }
85 });
64 });
86 });
65
87
66 var interval_id=0;
88 var interval_id=0;
General Comments 0
You need to be logged in to leave comments. Login now