PageRenderTime 69ms CodeModel.GetById 43ms RepoModel.GetById 1ms app.codeStats 0ms

/default/js/src/mura.feed.js

http://github.com/blueriver/MuraCMS
JavaScript | 201 lines | 147 code | 4 blank | 50 comment | 13 complexity | e28a4c797b7503579b95082ef29cc5e5 MD5 | raw file
Possible License(s): GPL-3.0, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception, MIT, BSD-3-Clause, CPL-1.0, Apache-2.0, 0BSD, LGPL-2.1
  1. /* This file is part of Mura CMS.
  2. Mura CMS is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, Version 2 of the License.
  5. Mura CMS is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with Mura CMS. If not, see <http://www.gnu.org/licenses/>.
  11. Linking Mura CMS statically or dynamically with other modules constitutes the preparation of a derivative work based on
  12. Mura CMS. Thus, the terms and conditions of the GNU General Public License version 2 ("GPL") cover the entire combined work.
  13. However, as a special exception, the copyright holders of Mura CMS grant you permission to combine Mura CMS with programs
  14. or libraries that are released under the GNU Lesser General Public License version 2.1.
  15. In addition, as a special exception, the copyright holders of Mura CMS grant you permission to combine Mura CMS with
  16. independent software modules (plugins, themes and bundles), and to distribute these plugins, themes and bundles without
  17. Mura CMS under the license of your choice, provided that you follow these specific guidelines:
  18. Your custom code
  19. • Must not alter any default objects in the Mura CMS database and
  20. • May not alter the default display of the Mura CMS logo within Mura CMS and
  21. • Must not alter any files in the following directories.
  22. /admin/
  23. /tasks/
  24. /config/
  25. /requirements/mura/
  26. /Application.cfc
  27. /index.cfm
  28. /MuraProxy.cfc
  29. You may copy and distribute Mura CMS with a plug-in, theme or bundle that meets the above guidelines as a combined work
  30. under the terms of GPL for Mura CMS, provided that you include the source code of that other code when and as the GNU GPL
  31. requires distribution of source code.
  32. For clarity, if you create a modified version of Mura CMS, you are not obligated to grant this special exception for your
  33. modified version; it is your choice whether to do so, or to make such modified version available under the GNU General Public License
  34. version 2 without this exception. You may, if you choose, apply this exception to your own modified versions of Mura CMS. */
  35. ;(function (root, factory) {
  36. if (typeof define === 'function' && define.amd) {
  37. // AMD. Register as an anonymous module.
  38. define(['Mura'], factory);
  39. } else if (typeof module === 'object' && module.exports) {
  40. // Node. Does not work with strict CommonJS, but
  41. // only CommonJS-like environments that support module.exports,
  42. // like Node.
  43. factory(require('Mura'));
  44. } else {
  45. // Browser globals (root is window)
  46. factory(root.Mura);
  47. }
  48. }(this, function (mura) {
  49. Mura.Feed=Mura.Core.extend({
  50. init:function(siteid,entityname){
  51. this.queryString= entityname + '/?';
  52. this.propIndex=0;
  53. this.entityname=entityname;
  54. return this;
  55. },
  56. fields:function(fields){
  57. this.queryString+='&fields=' + encodeURIComponent(fields);
  58. return this;
  59. },
  60. where:function(property){
  61. if(property){
  62. return this.andProp(property);
  63. }
  64. return this;
  65. },
  66. prop:function(property){
  67. return this.andProp(property);
  68. },
  69. andProp:function(property){
  70. this.queryString+='&' + encodeURIComponent(property) + '[' + this.propIndex + ']=';
  71. this.propIndex++;
  72. return this;
  73. },
  74. orProp:function(property){
  75. this.queryString+='&or[' + this.propIndex + ']&';
  76. this.propIndex++;
  77. this.queryString+= encodeURIComponent(property) + '[' + this.propIndex + ']=';
  78. this.propIndex++;
  79. return this;
  80. },
  81. isEQ:function(criteria){
  82. this.queryString+=encodeURIComponent(criteria);
  83. return this;
  84. },
  85. isNEQ:function(criteria){
  86. this.queryString+='neq^' + encodeURIComponent(criteria);
  87. return this;
  88. },
  89. isLT:function(criteria){
  90. this.queryString+='lt^' + encodeURIComponent(criteria);
  91. return this;
  92. },
  93. isLTE:function(criteria){
  94. this.queryString+='lte^' + encodeURIComponent(criteria);
  95. return this;
  96. },
  97. isGT:function(criteria){
  98. this.queryString+='gt^' + encodeURIComponent(criteria);
  99. return this;
  100. },
  101. isGTE:function(criteria){
  102. this.queryString+='gte^' + encodeURIComponent(criteria);
  103. return this;
  104. },
  105. isIn:function(criteria){
  106. this.queryString+='in^' + encodeURIComponent(criteria);
  107. return this;
  108. },
  109. isNotIn:function(criteria){
  110. this.queryString+='notin^' + encodeURIComponent(criteria);
  111. return this;
  112. },
  113. containsValue:function(criteria){
  114. this.queryString+='containsValue^' + encodeURIComponent(criteria);
  115. return this;
  116. },
  117. contains:function(criteria){
  118. this.queryString+='containsValue^' + encodeURIComponent(criteria);
  119. return this;
  120. },
  121. beginsWith:function(criteria){
  122. this.queryString+='begins^' + encodeURIComponent(criteria);
  123. return this;
  124. },
  125. endsWith:function(criteria){
  126. this.queryString+='ends^' + encodeURIComponent(criteria);
  127. return this;
  128. },
  129. openGrouping:function(criteria){
  130. this.queryString+='&openGrouping';
  131. return this;
  132. },
  133. andOpenGrouping:function(criteria){
  134. this.queryString+='&andOpenGrouping';
  135. return this;
  136. },
  137. closeGrouping:function(criteria){
  138. this.queryString+='&closeGrouping:';
  139. return this;
  140. },
  141. sort:function(property,direction){
  142. direction=direction || 'asc';
  143. if(direction == 'desc'){
  144. this.queryString+='&sort[' + this.propIndex + ']=-' + encodeURIComponent(property);
  145. } else {
  146. this.queryString+='&sort[' + this.propIndex + ']=+' + encodeURIComponent(property);
  147. }
  148. this.propIndex++;
  149. return this;
  150. },
  151. itemsPerPage:function(itemsPerPage){
  152. this.queryString+='&itemsPerPage=' + encodeURIComponent(itemsPerPage);
  153. return this;
  154. },
  155. maxItems:function(maxItems){
  156. this.queryString+='&maxItems=' + encodeURIComponent(maxItems);
  157. return this;
  158. },
  159. innerJoin:function(relatedEntity){
  160. this.queryString+='&innerJoin[' + this.propIndex + ']=' + encodeURIComponent(relatedEntity);
  161. this.propIndex++;
  162. return this;
  163. },
  164. leftJoin:function(relatedEntity){
  165. this.queryString+='&leftJoin[' + this.propIndex + ']=' + encodeURIComponent(relatedEntity);
  166. this.propIndex++;
  167. return this;
  168. },
  169. getQuery:function(){
  170. var self=this;
  171. return new Promise(function(resolve,reject) {
  172. Mura.ajax({
  173. type:'get',
  174. url:Mura.apiEndpoint + self.queryString,
  175. success:function(resp){
  176. var returnObj = new Mura.EntityCollection(resp.data);
  177. if(typeof resolve == 'function'){
  178. resolve(returnObj);
  179. }
  180. },
  181. error:reject
  182. });
  183. });
  184. }
  185. });
  186. }));