Guest User

Untitled

a guest
Apr 13th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. Test code:
  2.  
  3. /**
  4. * Create a new `Ti.UI.TabGroup`.
  5. */
  6. var tabGroup = Ti.UI.createTabGroup();
  7.  
  8. /**
  9. * Add the two created tabs to the tabGroup object.
  10. */
  11. tabGroup.addTab(createTab("Tab 1", "I am Window 1", "assets/images/tab1.png"));
  12. tabGroup.addTab(createTab("Tab 2", "I am Window 2", "assets/images/tab2.png"));
  13.  
  14. /**
  15. * Open the tabGroup
  16. */
  17. tabGroup.open();
  18.  
  19. /**
  20. * Creates a new Tab and configures it.
  21. *
  22. * @param {String} title The title used in the `Ti.UI.Tab` and it's included `Ti.UI.Window`
  23. * @param {String} message The title displayed in the `Ti.UI.Label`
  24. * @return {String} icon The icon used in the `Ti.UI.Tab`
  25. */
  26. function createTab(title, message, icon) {
  27. var win = Ti.UI.createWindow({
  28. title: title,
  29. backgroundColor: '#fff'
  30. });
  31.  
  32. var label = Ti.UI.createLabel({
  33. text: message,
  34. color: "#333",
  35. font: {
  36. fontSize: 20
  37. }
  38. });
  39.  
  40. win.add(label);
  41.  
  42. var tab = Ti.UI.createTab({
  43. title: title,
  44. icon: icon,
  45. window: win
  46. });
  47.  
  48. return tab;
  49. }
  50.  
  51.  
  52. // added during app creation. this will automatically login to
  53. // ACS for your application and then fire an event (see below)
  54. // when connected or errored. if you do not use ACS in your
  55. // application as a client, you should remove this block
  56. (function(){
  57. var ACS = require('ti.cloud'),
  58. env = Ti.App.deployType.toLowerCase() === 'production' ? 'production' : 'development',
  59. username = Ti.App.Properties.getString('acs-username-'+env),
  60. password = Ti.App.Properties.getString('acs-password-'+env);
  61.  
  62. // if not configured, just return
  63. if (!env || !username || !password) { return; }
  64. /**
  65. * Appcelerator Cloud (ACS) Admin User Login Logic
  66. *
  67. * fires login.success with the user as argument on success
  68. * fires login.failed with the result as argument on error
  69. */
  70. ACS.Users.login({
  71. login:username,
  72. password:password,
  73. }, function(result){
  74. if (env==='development') {
  75. Ti.API.info('ACS Login Results for environment `'+env+'`:');
  76. Ti.API.info(result);
  77. }
  78. if (result && result.success && result.users && result.users.length){
  79. Ti.App.fireEvent('login.success',result.users[0],env);
  80. Ti.API.info("Welcome Rakhi");
  81. //var phto1=Titanium.Filesystem.resourcesDirectory.getFile('tab1.png');
  82. var phto1 = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'tab1.png');
  83. ACS.Objects.create({
  84. classname: 'cars',
  85. fields: {
  86. make: 'nissan',
  87. color: 'blue',
  88. year: 2005,
  89. photo:phto1
  90. }
  91. }, function (e) {
  92. if (e.success) {
  93. var car = e.cars[0];
  94. Ti.API.info('Creation Success:\n' +
  95. 'id: ' + car.id + '\n' +
  96. 'make: ' + car.make + '\n' +
  97. 'color: ' + car.color + '\n' +
  98. 'year: ' + car.year + '\n' +
  99. 'photo: ' + car.photo + '\n' +
  100. 'created_at: ' + car.created_at);
  101.  
  102. var savedcarId= car.id;
  103.  
  104. Ti.API.info('Saved car ID' +savedcarId);
  105. var updatephto = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'tab2@3x.png');
  106. if(savedcarId){
  107.  
  108. Ti.API.info('Saved car ID+++' +savedcarId);
  109.  
  110.  
  111. ACS.Objects.update({
  112. classname: 'cars',
  113. id: savedcarId,
  114. fields: {
  115. color: 'purple',
  116. mileage: 10000,
  117. photo:updatephto
  118. }
  119. }, function (e) {
  120. if (e.success) {
  121. var car = e.cars[0];
  122. Ti.API.info('Update Successful:\n' +
  123. 'id: ' + car.id + '\n' +
  124. 'make: ' + car.make + '\n' +
  125. 'color: ' + car.color + '\n' +
  126. 'year: ' + car.year + '\n' +
  127. 'photo: ' + car.photo + '\n' +
  128. 'mileage: ' + car.mileage + '\n' +
  129. 'updated_at: ' + car.updated_at);
  130. } else {
  131. alert('Error:\n' +
  132. ((e.error && e.message) || JSON.stringify(e)));
  133. }
  134. });
  135.  
  136.  
  137.  
  138. }else{
  139.  
  140. Ti.API.info('Update falied');
  141. }
  142.  
  143.  
  144.  
  145. } else {
  146. alert('Error:\n' +
  147. ((e.error && e.message) || JSON.stringify(e)));
  148. }
  149. });
  150.  
  151.  
  152. } else {
  153. Ti.App.fireEvent('login.failed',result,env);
  154. }
  155. });
  156.  
  157. })();
  158.  
  159.  
  160.  
  161. Console logs:
  162. [INFO] : I/System.out: ActivityRecorder: before org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
  163. [INFO] : I/System.out: ActivityRecorder: before org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
  164. [INFO] : I/System.out: ActivityRecorder: after org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
  165. [INFO] : I/System.out: ActivityRecorder: after org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
  166. [INFO] : OpenGLRenderer: Initialized EGL, version 1.4
  167. [WARN] : EGL_emulation: eglSurfaceAttrib not implemente
  168. [INFO] : ACS Login Results for environment `development`:
  169. [INFO] : [object Object]
  170. [INFO] : Welcome Rakhi
  171. [INFO] : Creation Success:
  172. [INFO] : id: 5ac5e1fc04120102212c539a
  173. [INFO] : make: nissan
  174. [INFO] : color: blue
  175. [INFO] : year: 2005
  176. [INFO] : photo: [object Object]
  177. [INFO] : created_at: 2018-04-05T08:44:44+0000
  178. [INFO] : Saved car ID5ac5e1fc04120102212c539a
  179. [INFO] : Saved car ID+++5ac5e1fc04120102212c539a
  180. [WARN] : TiBaseFile: (main) [8229,8229] Method is not supported org.appcelerator.titanium.io.TiResourceFile : getParent
  181. [INFO] : Update Successful:
  182. [INFO] : id: 5ac5e1fc04120102212c539a
  183. [INFO] : make: nissan
  184. [INFO] : color: purple
  185. [INFO] : year: 2005
  186. [INFO] : photo: [object Object]
  187. [INFO] : mileage: 10000
  188. [INFO] : updated_at: 2018-04-05T08:44:47+0000
  189. [INFO] : APSAnalyticsService: Analytics Service Started
  190. [INFO] : APSAnalyticsService: Stopping Analytics Service
Add Comment
Please, Sign In to add comment