You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+85-76
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
3
**Table of Contents**
4
4
5
+
-[Usage](#usage)
5
6
-[Bower install](#bower-install)
6
7
-[Bower command](#bower-command)
7
8
-[Include as dependencie](#include-as-dependencie)
@@ -11,25 +12,98 @@
11
12
-[Auth](#auth)
12
13
-[Drupal 7](#drupal-7)
13
14
-[ToDo](#todo)
14
-
-[Usage](#usage)
15
15
16
16
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
17
17
18
-
Backbone.Drupal is a standalone plugin to connect Marionette JS and Backbone JS applications with Drupal 7/8
18
+
Backbone.Drupal is a standalone plugin to connect Marionette JS and Backbone JS applications with Drupal 7/8 to execute [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer) States to elaborate operation GET, POST, DELETE etc.
19
19
20
20
Originally Inspired in JS files from Drupal 7 Module <ahref="https://drupal.org/project/backbone"target="_blank">https://drupal.org/project/backbone</a>
21
21
22
-
### Bower install
22
+
# Usage
23
+
24
+
Check **test/index.html** for Drupal 8 example and **indexd7.html** for Drupal 7 example.
25
+
26
+
Before to test in Drupal 8 be sure the REST Resource Content for methods Get, Post, Update , Delete and Patch has json as format and Basic Auth as Authentication method.
27
+
28
+
You can the contributed module [Rest UI](https://www.drupal.org/project/restui) I recommend use the git version until Drupal 8 get his first official release.
29
+
30
+
Your configuration must look similar to following image.
// Define auth object, set crossDomain if is necessary
56
+
var Auth = new Backbone.Drupal.Auth({crossDomain: true});
57
+
// Request executed in sync mode
58
+
// If status is token further ajax will use the proper token
59
+
var auth_status = = Auth.login('admin', 'admin');
60
+
61
+
if(auth_status) {
62
+
63
+
// Check user retrieve
64
+
65
+
var User = new Backbone.Drupal.Models.User({uid: 1});
66
+
User.fetch({
67
+
success: function (user) {
68
+
// Check information retrived, could be used directly in a template
69
+
console.log(user.attributes.mail);
70
+
}
71
+
});
72
+
73
+
// Check users retrive
74
+
75
+
var Users = new Backbone.Drupal.Collections.UserIndex();
76
+
Users.fetch({
77
+
success: function (users) {
78
+
// Check information retrived, could be used directly in a template
79
+
console.log(users.models[0].attributes.uri);
80
+
}
81
+
});
82
+
} else {
83
+
alert('Auth Error');
84
+
}
85
+
});
86
+
87
+
</script>
88
+
89
+
</body>
90
+
</html>
91
+
92
+
````
93
+
94
+
Note: This plugin could be used with <ahref="requirejs.org"target="_blank">RequireJS</a>.
95
+
96
+
# Bower install
23
97
24
98
If you are using <atarget="_blank"href="http://bower.io/">Bower</a> you can download Backbone.drupal following this instructions
25
99
26
-
####Bower command
100
+
## Bower command
27
101
28
102
```
29
103
$ bower install backbone.drupal
30
104
```
31
105
32
-
####Include as dependencie
106
+
## Include as dependencie
33
107
34
108
If your application has a list of bower dependencies, you can include as dependency as shown below.
35
109
@@ -46,13 +120,13 @@ Check the releases section to verify the latest version.
46
120
47
121
```
48
122
49
-
###Features
123
+
# Features
50
124
51
-
####Cross-origin
125
+
##Cross-origin
52
126
53
127
Enable to have Drupal as Backend in a Domain backend.com and the Backbone/Marionette App in other domain frontend.com.
54
128
55
-
#####Drupal 8
129
+
### Drupal 8
56
130
57
131
Because the mode https://www.drupal.org/project/cors doesn't have a version for Drupal 8 yet and Drupal Core still doesn't have a solution for that I did a <ahref="https://www.drupal.org/files/issues/core-cors-headers-1869548-26.patch">patch</a> for .htacces to enable CORS request using jQuery documented in issue # https://www.drupal.org/node/1869548#comment-9120317
58
132
@@ -85,7 +159,7 @@ When issues https://www.drupal.org/node/1869548 and https://www.drupal.org/node/
85
159
86
160
More information at http://enable-cors.org/server_apache.html
87
161
88
-
######Auth
162
+
#### Auth
89
163
90
164
Drupal 8 doesn't implement yet the end point /user/login to enable remote login, this method in Drupal allow validate the credentials and request a CRS Token to be used in further request.
91
165
@@ -95,7 +169,7 @@ When function Auth is called the credentials are not validated, they are just en
95
169
96
170
Remember the credentials travel to your backend server **encoded** NOT **encrypted** for tha reason you **MUST** use a SSL certificate in your backend site to protect your users.
97
171
98
-
#####Drupal 7
172
+
### Drupal 7
99
173
100
174
In your Drupal Server you must setup <ahref="https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS"target="_blank">HTTP Access Control</a> to enable connection, below an example.
101
175
@@ -133,75 +207,10 @@ var Property = Backbone.Drupal.Models.Node.extend({
133
207
134
208
**REST**: Integration with Services Server type REST
135
209
136
-
###ToDo
210
+
# ToDo
137
211
138
212
<ul>
139
213
<li>Implement Collections for Taxonomies and Search</li>
140
214
<li>Create integration with module Restws in Drupal 7</li>
141
215
<li>Test Drupal 8 POST method and Views integrations.</li>
142
216
</ul>
143
-
144
-
### Usage
145
-
146
-
Check **test/index.html** for Drupal 8 example and **indexd7.html** for Drupal 7 example.
0 commit comments