Advertisement
BigRedDoge

Untitled

Mar 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.47 KB | None | 0 0
  1. function CostSort(sortType) {
  2. var table = ($('#purchasetable').children().toArray());
  3. var tablelength = table.length;
  4. var pricing = new Promise(function(resolve, reject) {
  5. var pricearr = [];
  6. var tablelength = table.length;
  7. for (var i = 0; i < tablelength; i++) {
  8. var price = parseFloat(($($(table[i]).children()[4]).text()).replace('$', ''));
  9. pricearr.push({
  10. id: ($($(table)[i]).attr('id')),
  11. price: (price)
  12. });
  13. }
  14. resolve (pricearr);
  15. });
  16. pricing.then((prices) => {
  17. if (sortType === "hightolow") {
  18. var highsort = (prices).sort(function(a, b) { return b.price - a.price });
  19. var tablesort = new Promise(function(resolve, reject) {
  20. var highhtml = [];
  21. for (var x = 0; x < highsort.length; x++) {
  22. var itemhtml = "<tr id='" + highsort[x].id + "' onclick=submitid(" +
  23. parseFloat(((highsort[x].id).replace('#', ''))) + ")>" +
  24. $($('#purchasetable').find('#' + highsort[x].id)).html() +
  25. "</tr>";
  26. highhtml.push(itemhtml);
  27. }
  28. resolve (highhtml);
  29. });
  30. tablesort.then((html) => {
  31. var sorting = new Promise(function(resolve, reject) {
  32. var sorted = html;
  33. $('#purchasetable').empty();
  34. resolve (sorted);
  35. });
  36. sorting.then((sorted) => {
  37. for (var z = 0; z < sorted.length; z++) {
  38. $('#purchasetable').append(sorted[z]);
  39. }
  40. });
  41. });
  42. } else if (sortType === "lowtohigh") {
  43. var lowsort = (prices).sort(function(a, b) { return a.price - b.price });
  44. var tablesort = new Promise(function(resolve, reject) {
  45. var lowhtml = [];
  46. for (var x = 0; x < lowsort.length; x++) {
  47. var itemhtml = "<tr id='" + lowsort[x].id + "' onclick=submitid(" +
  48. parseFloat(((lowsort[x].id).replace('#', ''))) + ")>" +
  49. $($('#purchasetable').find('#' + lowsort[x].id)).html() +
  50. "</tr>";
  51. lowhtml.push(itemhtml);
  52. }
  53. resolve (lowhtml);
  54. });
  55. tablesort.then((html) => {
  56. var sorting = new Promise(function(resolve, reject) {
  57. var sorted = html;
  58. $('#purchasetable').empty();
  59. resolve (sorted);
  60. });
  61. sorting.then((sorted) => {
  62. for (var z = 0; z < sorted.length; z++) {
  63. $('#purchasetable').append(sorted[z]);
  64. }
  65. });
  66. });
  67. }
  68. });
  69. }
  70.  
  71. function ProfitSort(sortType) {
  72. var table = ($('#purchasetable').children().toArray());
  73. var tablelength = table.length;
  74. var pricing = new Promise(function(resolve, reject) {
  75. var pricearr = [];
  76. var tablelength = table.length;
  77. for (var i = 0; i < tablelength; i++) {
  78. var price = parseFloat(($($(table[i]).children()[6]).text()).replace('$', ''));
  79. if (Boolean(price) === true) {
  80. pricearr.push({
  81. id: ($($(table)[i]).attr('id')),
  82. price: (price)
  83. });
  84. }
  85. }
  86. resolve (pricearr);
  87. });
  88. pricing.then((prices) => {
  89. if (sortType === "hightolow") {
  90. var highsort = (prices).sort(function(a, b) { return b.price - a.price });
  91. var tablesort = new Promise(function(resolve, reject) {
  92. var highhtml = [];
  93. for (var x = 0; x < highsort.length; x++) {
  94. var itemhtml = "<tr id='" + highsort[x].id + "' onclick=submitid(" +
  95. parseFloat(((highsort[x].id).replace('#', ''))) + ")>" +
  96. $($('#purchasetable').find('#' + highsort[x].id)).html() +
  97. "</tr>";
  98. highhtml.push(itemhtml);
  99. }
  100. resolve (highhtml);
  101. });
  102. tablesort.then((html) => {
  103. var sorting = new Promise(function(resolve, reject) {
  104. var sorted = html;
  105. $('#purchasetable').empty();
  106. resolve (sorted);
  107. });
  108. sorting.then((sorted) => {
  109. for (var z = 0; z < sorted.length; z++) {
  110. $('#purchasetable').append(sorted[z]);
  111. }
  112. });
  113. });
  114. } else if (sortType === "lowtohigh") {
  115. var lowsort = (prices).sort(function(a, b) { return a.price - b.price });
  116. var tablesort = new Promise(function(resolve, reject) {
  117. var lowhtml = [];
  118. for (var x = 0; x < lowsort.length; x++) {
  119. var itemhtml = "<tr id='" + lowsort[x].id + "' onclick=submitid(" +
  120. parseFloat(((lowsort[x].id).replace('#', ''))) + ")>" +
  121. $($('#purchasetable').find('#' + lowsort[x].id)).html() +
  122. "</tr>";
  123. lowhtml.push(itemhtml);
  124. }
  125. resolve (lowhtml);
  126. });
  127. tablesort.then((html) => {
  128. var sorting = new Promise(function(resolve, reject) {
  129. var sorted = html;
  130. $('#purchasetable').empty();
  131. resolve (sorted);
  132. });
  133. sorting.then((sorted) => {
  134. for (var z = 0; z < sorted.length; z++) {
  135. $('#purchasetable').append(sorted[z]);
  136. }
  137. });
  138. });
  139. }
  140. });
  141. }
  142.  
  143. function ProfitSort(sortType) {
  144. var table = ($('#purchasetable').children().toArray());
  145. var tablelength = table.length;
  146. var pricing = new Promise(function(resolve, reject) {
  147. var pricearr = [];
  148. var tablelength = table.length;
  149. for (var i = 0; i < tablelength; i++) {
  150. var price = parseFloat(($($(table[i]).children()[6]).text()).replace('$', ''));
  151. if (Boolean(price) === true) {
  152. pricearr.push({
  153. id: ($($(table)[i]).attr('id')),
  154. price: (price)
  155. });
  156. }
  157. }
  158. resolve (pricearr);
  159. });
  160. pricing.then((prices) => {
  161. if (sortType === "hightolow") {
  162. var highsort = (prices).sort(function(a, b) { return b.price - a.price });
  163. var tablesort = new Promise(function(resolve, reject) {
  164. var highhtml = [];
  165. for (var x = 0; x < highsort.length; x++) {
  166. var itemhtml = "<tr id='" + highsort[x].id + "' onclick=submitid(" +
  167. parseFloat(((highsort[x].id).replace('#', ''))) + ")>" +
  168. $($('#purchasetable').find('#' + highsort[x].id)).html() +
  169. "</tr>";
  170. highhtml.push(itemhtml);
  171. }
  172. resolve (highhtml);
  173. });
  174. tablesort.then((html) => {
  175. var sorting = new Promise(function(resolve, reject) {
  176. var sorted = html;
  177. $('#purchasetable').empty();
  178. resolve (sorted);
  179. });
  180. sorting.then((sorted) => {
  181. for (var z = 0; z < sorted.length; z++) {
  182. $('#purchasetable').append(sorted[z]);
  183. }
  184. });
  185. });
  186. } else if (sortType === "lowtohigh") {
  187. var lowsort = (prices).sort(function(a, b) { return a.price - b.price });
  188. var tablesort = new Promise(function(resolve, reject) {
  189. var lowhtml = [];
  190. for (var x = 0; x < lowsort.length; x++) {
  191. var itemhtml = "<tr id='" + lowsort[x].id + "' onclick=submitid(" +
  192. parseFloat(((lowsort[x].id).replace('#', ''))) + ")>" +
  193. $($('#purchasetable').find('#' + lowsort[x].id)).html() +
  194. "</tr>";
  195. lowhtml.push(itemhtml);
  196. }
  197. resolve (lowhtml);
  198. });
  199. tablesort.then((html) => {
  200. var sorting = new Promise(function(resolve, reject) {
  201. var sorted = html;
  202. $('#purchasetable').empty();
  203. resolve (sorted);
  204. });
  205. sorting.then((sorted) => {
  206. for (var z = 0; z < sorted.length; z++) {
  207. $('#purchasetable').append(sorted[z]);
  208. }
  209. });
  210. });
  211. }
  212. });
  213. }
  214.  
  215. function SaleSort(sortType) {
  216. var table = ($('#purchasetable').children().toArray());
  217. var tablelength = table.length;
  218. var pricing = new Promise(function(resolve, reject) {
  219. var pricearr = [];
  220. var tablelength = table.length;
  221. for (var i = 0; i < tablelength; i++) {
  222. var price = parseFloat(($($(table[i]).children()[5]).text()).replace('$', ''));
  223. if (Boolean(price) === true) {
  224. pricearr.push({
  225. id: ($($(table)[i]).attr('id')),
  226. price: (price)
  227. });
  228. }
  229. }
  230. resolve (pricearr);
  231. });
  232. pricing.then((prices) => {
  233. if (sortType === "hightolow") {
  234. var highsort = (prices).sort(function(a, b) { return b.price - a.price });
  235. var tablesort = new Promise(function(resolve, reject) {
  236. var highhtml = [];
  237. for (var x = 0; x < highsort.length; x++) {
  238. var itemhtml = "<tr id='" + highsort[x].id + "' onclick=submitid(" +
  239. parseFloat(((highsort[x].id).replace('#', ''))) + ")>" +
  240. $($('#purchasetable').find('#' + highsort[x].id)).html() +
  241. "</tr>";
  242. highhtml.push(itemhtml);
  243. }
  244. resolve (highhtml);
  245. });
  246. tablesort.then((html) => {
  247. var sorting = new Promise(function(resolve, reject) {
  248. var sorted = html;
  249. $('#purchasetable').empty();
  250. resolve (sorted);
  251. });
  252. sorting.then((sorted) => {
  253. for (var z = 0; z < sorted.length; z++) {
  254. $('#purchasetable').append(sorted[z]);
  255. }
  256. });
  257. });
  258. } else if (sortType === "lowtohigh") {
  259. var lowsort = (prices).sort(function(a, b) { return a.price - b.price });
  260. var tablesort = new Promise(function(resolve, reject) {
  261. var lowhtml = [];
  262. for (var x = 0; x < lowsort.length; x++) {
  263. var itemhtml = "<tr id='" + lowsort[x].id + "' onclick=submitid(" +
  264. parseFloat(((lowsort[x].id).replace('#', ''))) + ")>" +
  265. $($('#purchasetable').find('#' + lowsort[x].id)).html() +
  266. "</tr>";
  267. lowhtml.push(itemhtml);
  268. }
  269. resolve (lowhtml);
  270. });
  271. tablesort.then((html) => {
  272. var sorting = new Promise(function(resolve, reject) {
  273. var sorted = html;
  274. $('#purchasetable').empty();
  275. resolve (sorted);
  276. });
  277. sorting.then((sorted) => {
  278. for (var z = 0; z < sorted.length; z++) {
  279. $('#purchasetable').append(sorted[z]);
  280. }
  281. });
  282. });
  283. }
  284. });
  285. }
  286.  
  287. function WearSort(sortType) {
  288. var table = ($('#purchasetable').children().toArray());
  289. var tablelength = table.length;
  290. var pricing = new Promise(function(resolve, reject) {
  291. var pricearr = [];
  292. var tablelength = table.length;
  293. for (var i = 0; i < tablelength; i++) {
  294. var price = parseFloat($($(table[i]).children()[2]).text());
  295. if (Boolean(price) === true) {
  296. pricearr.push({
  297. id: ($($(table)[i]).attr('id')),
  298. price: (price)
  299. });
  300. }
  301. }
  302. resolve (pricearr);
  303. });
  304. pricing.then((prices) => {
  305. if (sortType === "hightolow") {
  306. var highsort = (prices).sort(function(a, b) { return b.price - a.price });
  307. var tablesort = new Promise(function(resolve, reject) {
  308. var highhtml = [];
  309. for (var x = 0; x < highsort.length; x++) {
  310. var itemhtml = "<tr id='" + highsort[x].id + "' onclick=submitid(" +
  311. parseFloat(((highsort[x].id).replace('#', ''))) + ")>" +
  312. $($('#purchasetable').find('#' + highsort[x].id)).html() +
  313. "</tr>";
  314. highhtml.push(itemhtml);
  315. }
  316. resolve (highhtml);
  317. });
  318. tablesort.then((html) => {
  319. var sorting = new Promise(function(resolve, reject) {
  320. var sorted = html;
  321. $('#purchasetable').empty();
  322. resolve (sorted);
  323. });
  324. sorting.then((sorted) => {
  325. for (var z = 0; z < sorted.length; z++) {
  326. $('#purchasetable').append(sorted[z]);
  327. }
  328. });
  329. });
  330. } else if (sortType === "lowtohigh") {
  331. var lowsort = (prices).sort(function(a, b) { return a.price - b.price });
  332. var tablesort = new Promise(function(resolve, reject) {
  333. var lowhtml = [];
  334. for (var x = 0; x < lowsort.length; x++) {
  335. var itemhtml = "<tr id='" + lowsort[x].id + "' onclick=submitid(" +
  336. parseFloat(((lowsort[x].id).replace('#', ''))) + ")>" +
  337. $($('#purchasetable').find('#' + lowsort[x].id)).html() +
  338. "</tr>";
  339. lowhtml.push(itemhtml);
  340. }
  341. resolve (lowhtml);
  342. });
  343. tablesort.then((html) => {
  344. var sorting = new Promise(function(resolve, reject) {
  345. var sorted = html;
  346. $('#purchasetable').empty();
  347. resolve (sorted);
  348. });
  349. sorting.then((sorted) => {
  350. for (var z = 0; z < sorted.length; z++) {
  351. $('#purchasetable').append(sorted[z]);
  352. }
  353. });
  354. });
  355. }
  356. });
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement