Keep off choosing any file
and click Attach button.
{"status":true,"data":"\u003cdiv class=\"form-item\" id=\"edit-upload-wrapper\"\u003e\n \u003clabel for=\"edit-upload\"\u003eAttach new file: \u003c\/label\u003e\n \u003cinput type=\"file\" name=\"files[upload]\" class=\"form-file\" id=\"edit-upload\" size=\"60\" \/\u003e\n\n \u003cdiv class=\"description\"\u003eThe maximum upload size is \u003cem\u003e3 MB\u003c\/em\u003e. Only files with the following extensions may be uploaded: \u003cem\u003ejpg jpeg gif png txt xls pdf ppt pps odt ods odp gz tgz patch diff zip test info po pot psd\u003c\/em\u003e. \u003c\/div\u003e\n\u003c\/div\u003e\n\u003cinput type=\"submit\" name=\"attach\" id=\"edit-attach\" value=\"Attach\" class=\"form-submit\" \/\u003e\n"}
Defining AJAX in the PHP arary!
if ($field['cardinality'] != 1) {
$parents = array_slice($element['#array_parents'], 0, -1); $new_path = 'file/ajax/' . implode('/', $parents) . '/' . $form['form_build_id']['#value']; $field_element = drupal_array_get_nested_value($form, $parents); $new_wrapper = $field_element['#id'] . '-ajax-wrapper';
foreach (element_children($element) as $key) { if (isset($element[$key]['#ajax'])) { $element[$key]['#ajax']['path'] = $new_path; $element[$key]['#ajax']['wrapper'] = $new_wrapper; } }
unset($element['#prefix'], $element['#suffix']); }
$(document).ready(function() {
$("#getData").click( function() {
$.getJSON("artistsRemote.cfc?method=getArtists&returnformat=json",
function(data) {
$("#artistsContent").empty();
$("#artistsTemplate").tmpl(
'<div class="fname">${fname}</div>' +
'<div class="lname">${lname}</div>'
'<div class="bio">${bio}</div>'
data
).appendTo("#artistsContent");
var nowIs = new Date().toLocaleString();
$('#lastLoad').html( nowIs );
});
});
});
is like if you decided to fix a chair, but did a apartment renovation
Magic that bings fun into the development
and make
clients happy!
var InvoiceItemModel = Backbone.Model.extend({
defaults: { description: '', price: 0, quantity: 1, },
calculateAmount: function() { return this.get('price') * this.get('quantity'); } });
var model = new InvoiceItemModel({
description: 'Toy Tracktor', price: 15, quantity: 1
});
hacker.set('name', "<script>alert('xss')</script>"); var escaped_name = hacker.escape('name');
// <script>alert('xss')</script>
var invoiceItemModel = Backbone.Model.extend({ idAttribute: "_id" });
invoiceItemModel._id = Math.random().toString(36).substr(2);
var id = invoiceItemModel._id;
var InvoiceItemCollection = Backbone.Collection.extend({ model: InvoiceItemModel });
var invoiceItemCollection = new InvoiceItemCollection([ {description: 'Wooden Toy House', price: 22, quantity: 3}, {description: 'Farm Animal Set', price: 17, quantity: 1} ]);
var model = invoiceItemCollection.at(2);
model.get('description'); // Farmer Figure
invoiceItemCollection.reset
([
{description: 'Wooden Toy House', price: 22, quantity: 3},
{description: 'Farm Animal Set', price: 17, quantity: 1}
]);
var amount = invoiceItemCollection.chain()
.map(function(model) {
return model.get('quantity') * model.get('price');
})
.reduce(function(memo, val) {
return memo + val;
})
.value(); // 83
var InvoiceItemView = Backbone.View.extend({ tagName: 'tr', template: _.template($('#item-row-template').html()), render: function() { var data = this.model.toJSON(); data.amount = this.model.calculateAmount(); this.$el.html(this.template(data)); return this; },
});
var InvoiceItemListView = Backbone.View.extend({ tagName: 'table', template: _.template($('#item-table-template').html()), render: function() { $(this.el).html(this.template()); _.each(this.collection.models, function(model, key) { this.append(model); }, this); return this; },
append: function(model) { var view = new InvoiceItemView({ model: model });
this.$el.append(view.render().el); } });
var InvoiceItemView = Backbone.View.extend({
// ... initialize: function() { this.listenTo(this.model, 'change', this.render, this); }
});
var InvoiceItemView = Backbone.View.extend({
//...
events: {
'click button.delete': 'delete',
},
function: delete() {
this.remove();
}
});
var Workspace = Backbone.Router.extend({ routes: { '': 'invoiceList', 'invoice': 'invoiceList', 'invoice/:id': 'invoicePage', },
invoiceList: function() { // ...
var view = new InvoiceItemListView({ collection: invoiceItemCollection }
$('body').html(view.render().el);
// ...
}
});
var PostModel = Backbone.Model.extend({ // Override id attribute. idAttribute: '_id',
// Define URL root to access model resource. urlRoot: function() { return 'http://example.com/posts/'; }
// Otherwise use url() method to provide full path
// to the model resource. });
var PostCollection = Backbone.Collection.extend({ model: PostModel,
// Define path to the collection resource. url: function() { return 'http://example.com/posts/'; } });
// Fetches data into a model. model.fetch();
// Saves a model. model.save();
// Destroys a model. model.destroy();
// Fetches data into a collection. collection.fetch();
// Adds models to a collection. collection.add(models);
// Removes specific models from collection. collection.remove(models);
// Pass success and error callbacks
model.fetch({
success: function(collection, response, options) {
},
error: function(collection, response, options){
}
});
// Create new NodeView collection. var viewCollection = new Drupal.Backbone.Collections.NodeView();
// Set Drupal View name. viewCollection.viewName = 'backbone_example';
// Fetch data from the collection. viewCollection.fetch({success: function() { console.log(viewCollection.toJSON()); });
resources:
'entity:node':
GET: { }
POST: { }
PATCH: { }
DELETE: { }
Content-type: application/hal+json
Accept: application/hal+json
<img src="http://example.com/logout">
<iframe src="http://example.com/logout"></iframe>
$.get('http://localhost/csrf/redirect').success(function(data) {});
$('#iframe').contents().find("body").html();
<form action="http://example.com/entity/node/<id>" method="DELETE"> <input type="submit" value="Delete" />
</form>
X-CSRF-Token: KzZD5jUyib4MmjTuRd6hZy34cW7GjcF-WnK-sbhRtFk
{ _links: { self: {
href: "http://example.com/node/5"
}, type: {
href: "http://example.com/rest/type/node/article"
}, http://example.com/rest/relation/node/article/uid: [{ href: "http://example.com/user/0" }] http://example.com/rest/relation/node/article/revision_uid: [{ href: "http://example.com/user/0" }] },
_embedded: { http://example.com/rest/relation/node/article/uid: [{ _links: { self: {
href: "http://example.com/user/0"
}, type: {
href: "http://example.com/rest/type/user/user"
} } },
// ... }, nid: [{ value: "5" }],
uuid: [{ value: "fbb5780d-3e72-4796-ab40-64c8765a8c61" }],
vid: [{ value: "5" }],
type: [{ value: "article" }],
// ... }
// Disable ajax cache
jQuery.ajaxSetup({ cache: false });
// Add REST service URL var appConfig = { baseURL: 'http://localhost/drupal-rest/', addURL: '', token: '' }
// Get token and save it $.get(appConfig.baseURL + 'rest/session/token') .done(function(data) { appConfig.token = data; });
// Override Backbone.sync to include a token and set headers
var sync = Backbone.sync; Backbone.sync = function(method, model, options) { options.beforeSend = function (xhr) { xhr.setRequestHeader('Content-type', 'application/hal+json'); xhr.setRequestHeader('Accept', 'application/hal+json'); xhr.setRequestHeader('X-CSRF-Token', appConfig.token); }; sync(method, model, options); };
// Define a mixin
var mixin = {
// Transform JSON generated by Drupal
parse: function(resp, options) { if (!_.isNull(resp)) { var id = this.idAttribute; _.each(resp, function(value, key) { if (_.isString(key) && key.charAt(0) != '_') { if (_.isArray(value)) { resp[key == 'nid' ? id : key] = value[0].value; } } }); delete resp.nid; } return resp; },
// Convert regular JSON into MongoDB extended one.
toExtendedJSON: function() {
var attrs = this.attributes;
var id = this.idAttribute;
_.each(attrs, function(value, key) {
if (_.isString(key) && key.charAt(0) != '_') {
attrs[key == id ? 'nid' : key] = [{ 'value': value }];
}
});
return attrs;
},
// Substute toJSON method when performing synchronization.
sync: function() {
var toJSON = this.toJSON;
this.toJSON = this.toExtendedJSON;
var ret = Backbone.sync.apply(this, arguments);
this.toJSON = toJSON;
return ret;
}
}
// Mix our mixin
_.extend(Backbone.Model.prototype, mixin);
(function ($, _, Backbone, Drupal, drupalSettings) {
"use strict"; // ...
Drupal.behaviors.edit = { attach: function (context) { // Initialize the Edit app once per page load. $('body').once('edit-init', initEdit); // Initialize models, collections and views. // Bind them to a DOM. // ... },
detach: function (context, settings, trigger) { if (trigger === 'unload') { // Deletes models, collections and views. deleteContainedModelsAndQueues($(context)); } } };
// ... })(jQuery, _, Backbone, Drupal, drupalSettings);