PageSourceSearch

https://app.menucontrol.com.br/directives/preparation_wizard/preparation_wizard.js

js menucontrol.com.br collected 2026-10-05 23:46:20 UTC 6,079 bytes, 182 lines download raw bytes

1app.directive("preparationWizard", function($modal, $log, PreparationsPathTo, preparationsService, IngredientsPreparationsPathTo, $timeout, IngredientsPathTo, UnitsPathTo, $location, PreparationCategoriesPathTo, auth, $rootScope, ingredientsService) {
2  return {
3    restrict: "E",
4    scope: {
5      preparation: "=",
6      preparationCategories: "="
7    },
8    templateUrl: "directives/preparation_wizard/preparation_wizard.html",
9    link: function(scope, element, attrs) {
10      var initialize = function() {
11        scope.busy = false;
12        scope.actualTab = 1;
13        scope.primary_units = UnitsPathTo.get_primary();
14      }
15
16      scope.openPreparationCategoryModal = function() {
17        var modalInstance = $modal.open({
18          templateUrl: "views/preparation_categories/modal_form.html",
19          controller: "preparation_categories_modal_form",
20          size: "sm"
21        })
22
23        // Return from modal
24        modalInstance.result.then(
25          function(preparation_category) {
26            scope.preparationCategories.push(preparation_category)
27            scope.preparation.preparation_category_id = preparation_category.id
28            scope.preparation.preparation_category = preparation_category
29          },
30          function() {
31            $log.info("Preparation category modal dismissed at: " + new Date())
32          }
33        )
34      }
35
36      scope.preparationSubmit = function(skip) {
37        if (!scope.preparation.id) {
38          PreparationsPathTo.save(
39            scope.preparation,
40            function success(preparation) {
41              Toastify({
42                text: 'Receita criada com sucesso!',
43                duration: 2000,
44                newWindow: true,
45                gravity: "top", // `top` or `bottom`
46                position: "right", // `left`, `center` or `right`
47                stopOnFocus: true, // Prevents dismissing of toast on hover
48                offset: {
49                  y: 65
50                },
51                style: {
52                  background: "#E4531A",
53                  borderRadius: "4px",
54                  opacity: "0.8"
55                },
56                onClick: function(){} // Callback after click
57              }).showToast()
58              scope.busy = false
59              Intercom("trackEvent", "receita_criou")
60              scope.preparation = preparation
61              preparationsService.addPreparation(preparation.id)
62              scope.moveTab(1, skip)
63            },
64            function error(error) {
65              scope.busy = false
66            }
67          )
68        } else {
69          PreparationsPathTo.update(
70            {
71              id: scope.preparation.id,
72              preparation: scope.preparation
73            },
74            function success(preparation) {
75              scope.busy = false
76              scope.preparation = preparation
77              ingredientsService.updateIngredient(preparation.ingredient_id)
78              preparationsService.updatePreparation(preparation.id)
79              scope.moveTab(1, skip)
80            },
81            function error(error) {
82              scope.busy = false
83            }
84          )
85        }
86      }
87
88      scope.moveTab = function(pos, skip) {
89        if (pos > 0) {
90          if(skip) {
91            Intercom("trackEvent", "Receita_wizard_passo_1_pulou")
92          } else {
93            Intercom("trackEvent", "Receita_wizard_passo_" + scope.actualTab)
94          }
95        }
96
97        if (pos > 0 && scope.actualTab == 3 || skip) {
98          $location.search('wizard', null)
99          $location.path("/preparations/" + scope.preparation.id + "/details")
100        } else {
101          scope.actualTab += pos
102        }
103      }
104
105      scope.removeIngredientsPreparation = function(ingredients_preparation_id) {
106        IngredientsPreparationsPathTo.remove(
107          {
108            id: ingredients_preparation_id
109          },
110          function success(preparation) {
111            scope.preparation = preparation
112            preparationsService.updatePreparation(scope.preparation.id)
113          },
114          function error() {}
115        )
116      }
117
118      scope.sendIntercomEvent = function(event) {
119        if (event == "clicouAdicionarIngReceita") {
120          Intercom("trackEvent", "Receita_ClickAddIngrediente")
121        }
122        if (event == "gerouFichaTecnicaReceita") {
123          Intercom("trackEvent", "Receita_GerouFichaTecnica")
124        }
125        if (event == "clicouCriarReceita") {
126          Intercom("trackEvent", "Receita_ClickCriar")
127        }
128        if (event == "atualizouRendimento") {
129          Intercom("trackEvent", "Receita_AtualizouRendimento")
130          $timeout(function() {
131            Intercom("update", {
132              last_request_at: parseInt(new Date().getTime() / 1000)
133            })
134          }, 600)
135        }
136      }
137
138      scope.sortableIngredientsOptions = {
139        helper: function(e, tr) {
140          var $originals = tr.children()
141          var $helper = tr.clone()
142          $helper.children().each(function(index) {
143            // Set helper cell sizes to match the original sizes
144            $(this).width($originals.eq(index).width())
145          })
146          return $helper
147        },
148        update: function(evnt, ui) {
149          $timeout(function() {
150            scope.preparation.ingredients.forEach(function(ing_prep, index) {
151              ing_prep.order = index
152            })
153            IngredientsPathTo.updateIngredientsOrder({
154              id: scope.preparation.ingredient_id,
155              ingredients: scope.preparation.ingredients
156            })
157          })
158        }
159      }
160
161      scope.estimateTotalGrammage = function() {
162       
163        scope.preparationSubmit()
164      }
165
166      scope.exportAssemblyPDF = function() {
167        var current_auth = auth.get()
168
169        window.location =
170          $rootScope.endpoint +
171          "preparations/" +
172          "print_assembly" +
173          ".pdf?user_email=" +
174          current_auth.user.email +
175          "&user_token=" +
176          current_auth.user.authentication_token
177      }
178
179      initialize()
180    }
181  }
182})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.