PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/bigdesk/_site/js/util/bigdesk_extension.js

https://gitlab.com/zouxc/elasticsearch-cn-out-of-box
JavaScript | 59 lines | 34 code | 3 blank | 22 comment | 4 complexity | e79db6e96b55515b52e86e5523b775c1 MD5 | raw file
  1. /*
  2. Copyright 2011-2014 Lukas Vlcek
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Override jQuery AJAX settings to use jsonp
  14. // Add some helper methods into both Model and Collection to support "baseUrl"
  15. Backbone.Model = Backbone.Model.extend({
  16. sync: function(method, model, options) {
  17. // options.timeout = 10000; // required, or the application won't pick up on 404 responses
  18. //options.dataType = 'jsonp';
  19. options.url = this.getBaseUrl() + this.url();
  20. return Backbone.sync(method, model, options);
  21. },
  22. getBaseUrl: function() {
  23. return this.get("baseUrl");
  24. },
  25. setBaseUrl: function(url) {
  26. this.set({baseUrl: url});
  27. },
  28. initialize: function(attributes, options) {
  29. if (options && options.baseUrl) {
  30. this.setBaseUrl(options.baseUrl);
  31. }
  32. }
  33. });
  34. Backbone.Collection = Backbone.Collection.extend({
  35. sync: function(method, model, options) {
  36. //options.dataType = 'jsonp';
  37. options.url = this.getBaseUrl() + this.url();
  38. return Backbone.sync(method, model, options);
  39. },
  40. // Did not find much information about how to store metadata with collection.
  41. // Direct set/get of property seems to work fine.
  42. getBaseUrl: function() {
  43. return this.baseUrl;
  44. },
  45. setBaseUrl: function(url) {
  46. this.baseUrl = url;
  47. },
  48. initialize: function(models, options) {
  49. if (options && options.baseUrl) {
  50. this.setBaseUrl(options.baseUrl);
  51. }
  52. }
  53. });