Skip to content

Commit 2fa45bf

Browse files
committed
created a nice UI for making new methods: split new method dialog up a bit to make resource selection easier to manage
1 parent fa135c7 commit 2fa45bf

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

css/apimenu.css

+23
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,26 @@ height: 16px;
288288
display: inline-block;
289289
overflow: hidden;
290290
}
291+
292+
293+
/*
294+
New Method popup dialog
295+
*/
296+
.method-content {
297+
position: absolute;
298+
background: #FFF;
299+
left: 100%;
300+
width: 550px;
301+
padding: 50px;
302+
border-top: 1px solid #EBEBEB;
303+
border-right: 1px solid #EBEBEB;
304+
border-bottom: 1px solid #EBEBEB;
305+
margin-left: -50px;
306+
307+
transition: top 0.3s;
308+
-moz-transition: top 0.3s;
309+
-o-transition: top 0.3s;
310+
-webkit-transition: top 0.3s;
311+
}
312+
313+
.method-content.form label { display: inline; }

js/views/apis/documentation.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ define([
2121
'views/apis/overview',
2222
'models/method',
2323
'views/modals/newresource',
24-
], function($, _, Backbone, Router, Vm, Mustache, Qtip, Session, docsTemplate, ApiModel, MethodsCollection, ResourceListView, MethodDetailView, ResourceDetailView, ResourceModel, MethodModel, hljs, ResourceForm, Modal, OverView, Method, NewResource){
24+
'text!templates/modals/newmethod.html'
25+
], function($, _, Backbone, Router, Vm, Mustache, Qtip, Session, docsTemplate, ApiModel, MethodsCollection, ResourceListView, MethodDetailView, ResourceDetailView, ResourceModel, MethodModel, hljs, ResourceForm, Modal, OverView, Method, NewResource, newMethodDialog){
2526
var NewApiPage = Backbone.View.extend({
2627
el: '.api-page-container',
2728
initialize: function () {
@@ -50,11 +51,53 @@ define([
5051

5152
this.modal = Modal.create({
5253
inline : {
54+
title : "Choose Resource",
55+
savetext : "Create method",
5356
from : $('.resource-list-container'),
5457
cloneDOM : true
5558
}
5659
});
5760

61+
var modalEl = this.modal.el,
62+
modalForm = $('form.inline-edit', modalEl),
63+
modalResourceAs = $('a[data-resource-id]', modalEl),
64+
resourceInput = $('<input type="hidden" name="resource" />');
65+
66+
// hide stuff from the resource list we don't want to see
67+
$('.notification', modalEl).remove();
68+
$('.modal-form-errors', modalEl).remove();
69+
70+
// slide method rows up to hide them
71+
$('.resource-list-container', modalEl).css('height', 'auto');
72+
$('.resource-submenu', modalEl).slideUp('fast');
73+
74+
// add a hidden input for the resource ID and rebind resource row click events to it
75+
modalForm.append(resourceInput);
76+
modalResourceAs.removeClass('active').on('click', function() {
77+
// store value for form submission
78+
resourceInput.val($(this).data('resource-id'));
79+
80+
// indicate current selection
81+
modalResourceAs.removeClass('active');
82+
$(this).addClass('active');
83+
84+
$('.modal-confirm', modalEl).show(); // OK to show submit button now
85+
$('.modal-title', modalEl).html("New Method"); // and change the title hint
86+
87+
// show and position the secondary dialog element we've injected below
88+
var topOffset = $(this).closest('li').position().top - parseInt($('.method-content', modalEl).css('padding-top'));
89+
$('.method-content', modalEl).css('top', topOffset).show();
90+
91+
return false;
92+
});
93+
94+
// inject the secondary dialog element for entering the method details
95+
// :TODO: errordef
96+
modalForm.append(Mustache.render(newMethodDialog, {}, {errorDef : ''}));
97+
98+
// hide confirm button until we've picked a resource
99+
$('.modal-confirm', modalEl).hide();
100+
58101
return false;
59102
},
60103
saveMethod: function (ev) {

templates/modals/newmethod.html

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
<form class="form new-method-form">
2-
3-
<div class="modal-header"><span class="icon modal-close-icon js-close-modal">&#88;</span></div>
4-
<div class="modal-content">
5-
<h3 class="modal-title">New method</h3>
6-
7-
<ul class="modal-form-errors">
8-
</ul>
1+
<div class="method-content form" style="display: none;">
2+
<div class="modal-form-errors">
3+
{{>errordef}}
4+
</div>
95

106
<input placeholder="Enter the name of your method" name="label" value="" type="text" required autofocus />
117
<label for="method">Select method type:</label>
@@ -17,10 +13,3 @@ <h3 class="modal-title">New method</h3>
1713
</select>
1814

1915
</div>
20-
<div class="modal-footer">
21-
<div class="modal-buttons">
22-
<button type="submit" class="btn btn-blue">Create method</button>
23-
</div>
24-
</div>
25-
26-
</form>

0 commit comments

Comments
 (0)