Skip to content

Commit

Permalink
fix #78
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkoperillo committed Apr 12, 2019
1 parent 65187db commit 1b21287
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,23 @@
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary" data-bind="click: send">Send</button>
</div>
<!--
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary" data-bind="click: saveBookmarkDialog">Save</button>
</div>
-->
<div class="btn-group">
<button type="button" class="btn btn-primary" aria-haspopup="true" aria-expanded="false" data-bind="click: saveBookmarkDialog">Save</button>
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="#" data-bind="click: saveAsBookmarkDialog">Save as</a></li>
</ul>
</div>


<div class="btn-group" role="group">
<button type="button" class="btn btn-primary" data-bind="click: reset">Reset</button>
</div>
Expand Down Expand Up @@ -171,7 +185,7 @@
</div>
<div class="panel-body">
<div class="form-group">
Name <input type="text" class="form-control" data-bind="value: bookmarkSelected.name"></input>
Name <input type="text" class="form-control" data-bind="value: bookmarkName"></input>
</div>
<div class="form-group">
Folder <select class="form-control" data-bind="options: folders, optionsText: 'name', optionsValue: 'id', optionsCaption: 'None', value: folderSelected"></select>
Expand Down
21 changes: 17 additions & 4 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a
bookmarks: ko.observableArray(),
folders: ko.observableArray(),
folderSelected: ko.observable(),
bookmarkName: ko.observable(),
methods: ko.observableArray(['GET','POST','PUT','DELETE','HEAD','OPTIONS','CONNECT','TRACE','PATCH']),

// request panel flags
Expand All @@ -76,6 +77,8 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a
showContextDialog: ko.observable(false),
showCreateContextDialog: ko.observable(false),
showConfirmDialog: ko.observable(false),

saveAsNewBookmark: ko.observable(false),

dialogConfirmMessage: ko.observable(),
contextName: ko.observable(),
Expand Down Expand Up @@ -235,7 +238,7 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a
}

const _saveBookmark = (bookmark, internal=false) => {
if(Resting.bookmarkCopy && !internal) {
if(Resting.bookmarkCopy && !Resting.saveAsNewBookmark() && !internal) {
// if edit a bookmark
if(bookmark.folder) {
const oldFolder = Resting.bookmarkCopy.folder;
Expand Down Expand Up @@ -299,8 +302,9 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a
_extractModelFromVM(Resting.request.headers()), _extractModelFromVM(Resting.request.querystring()), Resting.request.bodyType(),
body(Resting.request.bodyType()),_authentication(), Resting.request.context());

const bookmarkId = Resting.bookmarkCopy ? Resting.bookmarkCopy.id : new Date().toString();
const bookmarkObj = bookmarkProvider.makeBookmark(bookmarkId, req, validateBookmarkName(Resting.bookmarkSelected.name()), Resting.folderSelected());
const bookmarkId = Resting.bookmarkCopy && !Resting.saveAsNewBookmark() ? Resting.bookmarkCopy.id : new Date().toString();
const bookmarkObj = bookmarkProvider.makeBookmark(bookmarkId, req, validateBookmarkName(Resting.bookmarkName()), Resting.folderSelected());
Resting.bookmarkSelected.name(Resting.bookmarkName());
_saveBookmark(bookmarkObj);

// close the dialog
Expand All @@ -310,7 +314,7 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a
const reset = () => {
Resting.bookmarkCopy = null;
Resting.folderSelected('');

Resting.bookmarkName('');
Resting.bookmarkSelected.name('');
Resting.bookmarkSelected.id('');

Expand Down Expand Up @@ -454,6 +458,14 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a

const saveBookmarkDialog = () => {
Resting.showBookmarkDialog(true);
Resting.saveAsNewBookmark(false);
Resting.bookmarkName(Resting.bookmarkSelected.name());
};

const saveAsBookmarkDialog = () => {
Resting.showBookmarkDialog(true);
Resting.saveAsNewBookmark(true);
Resting.bookmarkName('');
};

const dismissSaveBookmarkDialog = () => {
Expand Down Expand Up @@ -586,6 +598,7 @@ requirejs(['jquery','app/storage','knockout','knockout-secure-binding','hjls','a
Resting.creditsDialog = creditsDialog;
Resting.contextDialog = contextDialog;
Resting.saveBookmarkDialog = saveBookmarkDialog;
Resting.saveAsBookmarkDialog = saveAsBookmarkDialog;

Resting.dismissSaveBookmarkDialog = dismissSaveBookmarkDialog;
Resting.dismissCreditsDialog = dismissCreditsDialog;
Expand Down

0 comments on commit 1b21287

Please sign in to comment.