@@ -21,7 +21,8 @@ define([
21
21
'views/apis/overview' ,
22
22
'models/method' ,
23
23
'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 ) {
25
26
var NewApiPage = Backbone . View . extend ( {
26
27
el : '.api-page-container' ,
27
28
initialize : function ( ) {
@@ -50,11 +51,53 @@ define([
50
51
51
52
this . modal = Modal . create ( {
52
53
inline : {
54
+ title : "Choose Resource" ,
55
+ savetext : "Create method" ,
53
56
from : $ ( '.resource-list-container' ) ,
54
57
cloneDOM : true
55
58
}
56
59
} ) ;
57
60
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
+
58
101
return false ;
59
102
} ,
60
103
saveMethod : function ( ev ) {
0 commit comments