Guest User

Untitled

a guest
Aug 15th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. Sencha touch 2.0 can't set activeitem on viewport
  2. App.view.Viewport.setActiveItem("App.view.user.Index",{
  3. type: "slide",
  4. direction: "left"
  5. });
  6.  
  7. this.App.view.Viewport.setActiveItem("App.view.user.Index",{
  8. type: "slide",
  9. direction: "left"
  10. });
  11.  
  12. Uncaught TypeError: Object function () {
  13. return this.constructor.apply(this, arguments);
  14. } has no method 'setActiveItem'
  15.  
  16. Ext.Loader.setConfig(
  17. {
  18. enabled: true ,
  19. paths:{
  20. //set application path
  21. App: 'app'
  22. }
  23.  
  24. });
  25.  
  26. // Main application entry point
  27. Ext.application({
  28. name: 'App',
  29. //Define all models and controllers in the application
  30. //Views do not have to be defined these are defined in the controllers
  31.  
  32. //Models
  33.  
  34. //Controllers
  35. controllers: ['User'],
  36. //automatically create a viewport(template) instance/object app/Viewport.js
  37. autoCreateViewport: true,
  38. launch: function() {
  39.  
  40.  
  41. }
  42. });
  43.  
  44. Ext.define('App.view.Viewport', {
  45. extend: 'Ext.viewport.Default',
  46. xtype: "Viewport",
  47.  
  48.  
  49. config: {
  50.  
  51.  
  52. fullscreen:true,
  53. layout: "card",
  54. items:[
  55. {
  56. xtype: "panel",
  57. scrollable:true,
  58. items: [
  59. {
  60. xtype:"toolbar",
  61. title:"Test app"
  62. },
  63. {
  64. xtype:"UserLoginView",
  65. id: "LoginForm"
  66. }
  67. ]
  68. }
  69. ]
  70. }
  71.  
  72. });
  73.  
  74. //Define controller name
  75. Ext.define('App.controller.User', {
  76. //Extend the controller class
  77. extend: 'Ext.app.Controller',
  78. views: ['user.Login','user.Index'],
  79. refs: [
  80. {
  81. selector:"#userLogin",
  82. ref: 'LoginUserLogin'
  83. },
  84. {
  85. selector:"#userPassword",
  86. ref: "LoginUserPassword"
  87. },
  88. {
  89. selector: "Viewport",
  90. ref: "Viewport"
  91. },
  92. {
  93. selector: "UserIndex",
  94. ref: "UserIndex"
  95. }
  96. ],
  97. //define associated views with this controller
  98.  
  99.  
  100. init: function()
  101. {
  102. //do something and setup listeners
  103.  
  104. //setup listeners
  105. this.control({
  106. '#UserLoginButon' : {
  107. tap : this.login
  108.  
  109. }
  110. });
  111. },
  112.  
  113. //handle
  114. login : function (object)
  115. {
  116. //iniate loading screen for user
  117. var loadingScreen = new Ext.LoadMask(Ext.getBody(),{msg: ""});
  118. loadingScreen.show();
  119.  
  120.  
  121. //get form values
  122. var username = this.getLoginUserLogin().getValue();
  123. var password = this.getLoginUserPassword().getValue();
  124.  
  125. //check for empty fields
  126. if(username == "" || password == "")
  127. {
  128. loadingScreen.hide();
  129. Ext.Msg.alert("Foutmelding","Je dient alle velden in te vullen.");
  130. }
  131. else
  132. {
  133. Ext.Ajax.request(
  134. {
  135. url: '../backend/users/login/'+username+'/'+password,
  136. method: 'post',
  137. failure : function(response)
  138. {
  139. loadingScreen.hide();
  140. data = Ext.decode(response.responseText);
  141. Ext.Msg.alert('Login Error', data.errorMessage, Ext.emptyFn);
  142. },
  143. success: function(response, opts)
  144. {
  145. data = Ext.decode(response.responseText);
  146.  
  147. if (data == true)
  148. {
  149. loadingScreen.hide();
  150. Ext.Msg.alert("ingelogd!","welkom");
  151.  
  152. //THIS IS WHERE IT GOES WRONG
  153. App.view.Viewport.setActiveItem("App.view.user.Index",{
  154. type: "slide",
  155. direction: "left"
  156. });
  157.  
  158.  
  159.  
  160.  
  161. } else
  162. {
  163. loadingScreen.hide();
  164. Ext.Msg.alert("Foutmelding","Gebruikersnaam of wachtwoord klopt niet.");
  165. }
  166. }
  167. });
  168.  
  169.  
  170.  
  171.  
  172. }
  173. console.log(App);
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. },
  184. loginRequest : function (username, password)
  185. {
  186.  
  187. }
  188.  
  189.  
  190.  
  191. });
  192.  
  193. Ext.Loader.setConfig({enabled:true});
  194. Ext.application({
  195. name: 'MyApp',
  196. controllers: ['MyController'],
  197. autoCreateViewport: true,
  198. launch: function() {
  199. console.log('launch!');
  200. }
  201. });
  202.  
  203. Ext.define('MyApp.view.Viewport', {
  204. extend: 'Ext.Container',
  205. xtype: 'my-viewport',
  206. config: {
  207. layout: {
  208. type: 'card',
  209. animation: {
  210. type: 'slide',
  211. direction: 'left'
  212. }
  213. },
  214. fullscreen: true,
  215. items: [{xtype: 'my-list'}, {xtype: 'my-detail'}]
  216. }
  217. });
  218.  
  219. Ext.define('MyApp.controller.MyController', {
  220. extend: 'Ext.app.Controller',
  221. views: ['Navbar', 'List', 'Detail'],
  222. init: function() {
  223. console.log('MyController init');
  224.  
  225. this.control({
  226. 'button[go]': {
  227. tap: function(btn) {
  228. viewport = Ext.ComponentQuery.query('my-viewport');
  229. target = Ext.ComponentQuery.query(btn.go);
  230. viewport[0].setActiveItem(target[0]);
  231. }
  232. }
  233. });
  234. }
  235. });
  236.  
  237. {
  238. xtype: 'button',
  239. text: 'detail view!',
  240. go: 'my-detail',
  241. width: '20%'
  242. }
  243.  
  244. var indexPanel = Ext.create('App.view.user.Index');
  245. Ext.Viewport.add(indexPanel)
  246. Ext.Viewport.setActiveItem(indexPanel)
Add Comment
Please, Sign In to add comment