##// END OF EJS Templates
Merge pull request #7576 from minrk/warn-overwrite...
Matthias Bussonnier -
r20209:b29264c2 merge
parent child Browse files
Show More
@@ -78,6 +78,7 b' define(['
78 this.tooltip = new tooltip.Tooltip(this.events);
78 this.tooltip = new tooltip.Tooltip(this.events);
79 this.ws_url = options.ws_url;
79 this.ws_url = options.ws_url;
80 this._session_starting = false;
80 this._session_starting = false;
81 this.last_modified = null;
81
82
82 // Create default scroll manager.
83 // Create default scroll manager.
83 this.scroll_manager = new scrollmanager.ScrollManager(this);
84 this.scroll_manager = new scrollmanager.ScrollManager(this);
@@ -1865,7 +1866,10 b' define(['
1865 * Save this notebook on the server. This becomes a notebook instance's
1866 * Save this notebook on the server. This becomes a notebook instance's
1866 * .save_notebook method *after* the entire notebook has been loaded.
1867 * .save_notebook method *after* the entire notebook has been loaded.
1867 */
1868 */
1868 Notebook.prototype.save_notebook = function () {
1869 Notebook.prototype.save_notebook = function (check_last_modified) {
1870 if (check_last_modified === undefined) {
1871 check_last_modified = true;
1872 }
1869 if (!this._fully_loaded) {
1873 if (!this._fully_loaded) {
1870 this.events.trigger('notebook_save_failed.Notebook',
1874 this.events.trigger('notebook_save_failed.Notebook',
1871 new Error("Load failed, save is disabled")
1875 new Error("Load failed, save is disabled")
@@ -1891,12 +1895,46 b' define(['
1891 var start = new Date().getTime();
1895 var start = new Date().getTime();
1892
1896
1893 var that = this;
1897 var that = this;
1894 return this.contents.save(this.notebook_path, model).then(
1898 var _save = function () {
1895 $.proxy(this.save_notebook_success, this, start),
1899 return that.contents.save(that.notebook_path, model).then(
1900 $.proxy(that.save_notebook_success, that, start),
1896 function (error) {
1901 function (error) {
1897 that.events.trigger('notebook_save_failed.Notebook', error);
1902 that.events.trigger('notebook_save_failed.Notebook', error);
1898 }
1903 }
1899 );
1904 );
1905 };
1906
1907 if (check_last_modified) {
1908 return this.contents.get(this.notebook_path, {content: false}).then(
1909 function (data) {
1910 var last_modified = new Date(data.last_modified);
1911 if (last_modified > that.last_modified) {
1912 dialog.modal({
1913 notebook: that,
1914 keyboard_manager: that.keyboard_manager,
1915 title: "Notebook changed",
1916 body: "Notebook has changed since we opened it. Overwrite the changed file?",
1917 buttons: {
1918 Cancel: {},
1919 Overwrite: {
1920 class: 'btn-danger',
1921 click: function () {
1922 _save();
1923 }
1924 },
1925 }
1926 });
1927 } else {
1928 return _save();
1929 }
1930 }, function (error) {
1931 // maybe it has been deleted or renamed? Go ahead and save.
1932 return _save();
1933 }
1934 );
1935 } else {
1936 return _save();
1937 }
1900 };
1938 };
1901
1939
1902 /**
1940 /**
@@ -1907,6 +1945,7 b' define(['
1907 */
1945 */
1908 Notebook.prototype.save_notebook_success = function (start, data) {
1946 Notebook.prototype.save_notebook_success = function (start, data) {
1909 this.set_dirty(false);
1947 this.set_dirty(false);
1948 this.last_modified = new Date(data.last_modified);
1910 if (data.message) {
1949 if (data.message) {
1911 // save succeeded, but validation failed.
1950 // save succeeded, but validation failed.
1912 var body = $("<div>");
1951 var body = $("<div>");
@@ -2150,6 +2189,7 b' define(['
2150 this.set_dirty(false);
2189 this.set_dirty(false);
2151 this.scroll_to_top();
2190 this.scroll_to_top();
2152 this.writable = data.writable || false;
2191 this.writable = data.writable || false;
2192 this.last_modified = new Date(data.last_modified);
2153 var nbmodel = data.content;
2193 var nbmodel = data.content;
2154 var orig_nbformat = nbmodel.metadata.orig_nbformat;
2194 var orig_nbformat = nbmodel.metadata.orig_nbformat;
2155 var orig_nbformat_minor = nbmodel.metadata.orig_nbformat_minor;
2195 var orig_nbformat_minor = nbmodel.metadata.orig_nbformat_minor;
General Comments 0
You need to be logged in to leave comments. Login now