<commit_before>import Ember from 'ember';
export default Ember.Mixin.create({
    _createNewChargeRecord: function(quantityCharged, pricingId) {
        return new Ember.RSVP.Promise(function(resolve, reject) {
            this.store.find('pricing', pricingId.substr(8)).then(function(item) {
                var newCharge = this.store.createRecord('proc-charge', {                                                                           
                    quantity: quantityCharged,
                    pricingItem: item                    
                });
                newCharge.save().then(function(chargeRecord) {
                    var charges = this.get('charges');
                    charges.addObject(chargeRecord);
                    resolve();
                }.bind(this), reject);
            }.bind(this), reject);            
        }.bind(this), '_createNewChargeRecord with pricingId:'+pricingId);
    },
    
    actions: {
        addCharge: function(charge) {
            var charges = this.get('charges');
            charges.addObject(charge);
            this.send('update', true);
            this.send('closeModal');
        },
        
        deleteCharge: function(model) {
            var chargeToDelete = model.get('chargeToDelete'),
                charges = this.get('charges');
            charges.removeObject(chargeToDelete);
            chargeToDelete.destroyRecord();
            this.send('update', true);
            this.send('closeModal');
        },
        
        showAddCharge: function() {
            var newCharge = this.get('store').createRecord('proc-charge',{
                quantity: 1,
                pricingCategory: this.get('chargePricingCategory')
            });
            this.send('openModal', this.get('chargeRoute'), newCharge);
        },
        
        showEditCharge: function(charge) {
            charge.set('pricingCategory', this.get('chargePricingCategory'));
            this.send('openModal', this.get('chargeRoute'), charge);            
        },
        
        showDeleteCharge: function(charge) {
            this.send('openModal', 'dialog', Ember.Object.create({
                confirmAction: 'deleteCharge',
                title: 'Delete Charge Item',
                message: 'Are you sure you want to delete this charged item?',
                chargeToDelete: charge,
                updateButtonAction: 'confirm',
                updateButtonText: 'Ok'
            }));                 
        }
    },
    
    canAddCharge: function() {
        return this.currentUserCan('add_charge');
    }.property(),
    
    /**
     * Returns pricing list without object types
     * Used for labs and imaging where the labs and imaging types are
     * directly in the price list.
     */
    chargesPricingList: function() {
        var pricingList = this.get('pricingList'),
            pricingTypeForObjectType = this.get('pricingTypeForObjectType');
        return pricingList.filter(function(item) {
            return (item.type !== pricingTypeForObjectType);
        });
    }.property('pricingList','pricingTypeForObjectType'),

    
    chargeRoute: null,
    
    findChargeForPricingItem: function(pricingItem) {
        var charges = this.get('charges'),
            chargeForItem = charges.find(function(charge) {
                var chargePricingItemId = charge.get('pricingItem.id');
                return (pricingItem._id.substr(8) === chargePricingItemId);
            });
        return chargeForItem;
    },
    
    newObjectType: false,
    
    objectTypeChanged: function(objectTypeNameField, typeField) {
        var objectTypeName = this.get(objectTypeNameField),
            objectType = this.get(typeField);
        if (!Ember.isEmpty(objectType)) {
            this.set('newObjectType', false);
            if (objectType.get('name') !== objectTypeName) {
                this.set(objectTypeNameField, objectType.get('name'));
            }
        } else {
            this.set('newObjectType', true);
        }
    },

    /**
     * Returns object types out of the pricing list.
     * Used for labs and imaging where the labs and imaging types are
     * directly in the price list.
     */
    objectTypeList: function() {
        var pricingList = this.get('pricingList'),            
            pricingTypeForObjectType = this.get('pricingTypeForObjectType'),
            userCanAddPricingTypes = this.get('userCanAddPricingTypes'),
            returnList = Ember.Object.create({
                value: [],
                userCanAdd: userCanAddPricingTypes
            });        
        if (!Ember.isEmpty(pricingList)) {
            returnList.set('value', pricingList.filterBy('type', pricingTypeForObjectType));
        }
        return returnList;
    }.property('pricingList','pricingTypeForObjectType','pricingTypeValues'),
    
    objectTypeNameChanged: function(objectTypeNameField, selectedField) {
        var objectTypeName = this.get(objectTypeNameField);
        if (objectTypeName instanceof Object) {
            this.set(selectedField, objectTypeName);
        }
    },
    
    organizeByType: Ember.computed.alias('pricingTypes.organizeByType'),
        
    pricingTypeList: function() {
        var pricingTypeValues = this.get('pricingTypeValues'),
            pricingTypeForObjectType = this.get('pricingTypeForObjectType');
        pricingTypeValues = pricingTypeValues.filter(function(pricingType) {
            return pricingType !== pricingTypeForObjectType;
        });
        return pricingTypeValues;
    }.property('pricingTypeValues','pricingTypeForObjectType'),
    
    pricingTypeValues: Ember.computed.alias('pricingTypes.value'),
    
    saveNewPricing: function(pricingName, pricingCategory, priceObjectToSet) {
        return new Ember.RSVP.Promise(function(resolve, reject) {
            var newPricing,
                pricingTypeForObjectType = this.get('pricingTypeForObjectType');
            newPricing = this.store.createRecord('pricing', {
                name: pricingName,
                category: pricingCategory,
                type: pricingTypeForObjectType
            });
            newPricing.save().then(function() {
                this.get('pricingList').addObject({
                    _id: 'pricing_'+ newPricing.get('id'),
                    name: newPricing.get('name')
                });
                this.set(priceObjectToSet, newPricing);
                resolve();
            }.bind(this), reject);
        }.bind(this), 'saveNewPricing for: '+pricingName);        
    },
       
    selectedObjectTypeChanged: function(selectedField, typeField) {
        var selectedItem = this.get(selectedField);
        if (!Ember.isEmpty(selectedItem)) {            
            this.store.find('pricing', selectedItem._id.substr(8)).then(function(item) {
                this.set(typeField, item);
            }.bind(this));
        } else {
           this.set(typeField);
        }
    },
  
    showAddCharge: function() {
        var canAddCharge = this.get('canAddCharge'), 
            organizeByType = this.get('organizeByType');
        if (canAddCharge) {
            return !organizeByType;
        } else {
            return false;<commit_msg>Changed objectType functions to only fire on new<commit_after>import Ember from 'ember';
export default Ember.Mixin.create({
    _createNewChargeRecord: function(quantityCharged, pricingId) {
        return new Ember.RSVP.Promise(function(resolve, reject) {
            this.store.find('pricing', pricingId.substr(8)).then(function(item) {
                var newCharge = this.store.createRecord('proc-charge', {                                                                           
                    quantity: quantityCharged,
                    pricingItem: item                    
                });
                newCharge.save().then(function(chargeRecord) {
                    var charges = this.get('charges');
                    charges.addObject(chargeRecord);
                    resolve();
                }.bind(this), reject);
            }.bind(this), reject);            
        }.bind(this), '_createNewChargeRecord with pricingId:'+pricingId);
    },
    
    actions: {
        addCharge: function(charge) {
            var charges = this.get('charges');
            charges.addObject(charge);
            this.send('update', true);
            this.send('closeModal');
        },
        
        deleteCharge: function(model) {
            var chargeToDelete = model.get('chargeToDelete'),
                charges = this.get('charges');
            charges.removeObject(chargeToDelete);
            chargeToDelete.destroyRecord();
            this.send('update', true);
            this.send('closeModal');
        },
        
        showAddCharge: function() {
            var newCharge = this.get('store').createRecord('proc-charge',{
                quantity: 1,
                pricingCategory: this.get('chargePricingCategory')
            });
            this.send('openModal', this.get('chargeRoute'), newCharge);
        },
        
        showEditCharge: function(charge) {
            charge.set('pricingCategory', this.get('chargePricingCategory'));
            this.send('openModal', this.get('chargeRoute'), charge);            
        },
        
        showDeleteCharge: function(charge) {
            this.send('openModal', 'dialog', Ember.Object.create({
                confirmAction: 'deleteCharge',
                title: 'Delete Charge Item',
                message: 'Are you sure you want to delete this charged item?',
                chargeToDelete: charge,
                updateButtonAction: 'confirm',
                updateButtonText: 'Ok'
            }));                 
        }
    },
    
    canAddCharge: function() {
        return this.currentUserCan('add_charge');
    }.property(),
    
    /**
     * Returns pricing list without object types
     * Used for labs and imaging where the labs and imaging types are
     * directly in the price list.
     */
    chargesPricingList: function() {
        var pricingList = this.get('pricingList'),
            pricingTypeForObjectType = this.get('pricingTypeForObjectType');
        return pricingList.filter(function(item) {
            return (item.type !== pricingTypeForObjectType);
        });
    }.property('pricingList','pricingTypeForObjectType'),

    
    chargeRoute: null,
    
    findChargeForPricingItem: function(pricingItem) {
        var charges = this.get('charges'),
            chargeForItem = charges.find(function(charge) {
                var chargePricingItemId = charge.get('pricingItem.id');
                return (pricingItem._id.substr(8) === chargePricingItemId);
            });
        return chargeForItem;
    },
    
    newObjectType: false,
    
    objectTypeChanged: function(objectTypeNameField, typeField) {
        var isNew = this.get('isNew'),
            objectTypeName = this.get(objectTypeNameField),
            objectType = this.get(typeField);
        if (isNew) {
            if (!Ember.isEmpty(objectType)) {
                this.set('newObjectType', false);
                if (objectType.get('name') !== objectTypeName) {
                    this.set(objectTypeNameField, objectType.get('name'));
                }
            } else {
                this.set('newObjectType', true);
            }
        }
    },

    /**
     * Returns object types out of the pricing list.
     * Used for labs and imaging where the labs and imaging types are
     * directly in the price list.
     */
    objectTypeList: function() {
        var pricingList = this.get('pricingList'),            
            pricingTypeForObjectType = this.get('pricingTypeForObjectType'),
            userCanAddPricingTypes = this.get('userCanAddPricingTypes'),
            returnList = Ember.Object.create({
                value: [],
                userCanAdd: userCanAddPricingTypes
            });        
        if (!Ember.isEmpty(pricingList)) {
            returnList.set('value', pricingList.filterBy('type', pricingTypeForObjectType));
        }
        return returnList;
    }.property('pricingList','pricingTypeForObjectType','pricingTypeValues'),
    
    objectTypeNameChanged: function(objectTypeNameField, selectedField) {
        var isNew = this.get('isNew'),
            objectTypeName = this.get(objectTypeNameField);
        if (isNew && objectTypeName instanceof Object) {
            this.set(selectedField, objectTypeName);
        }
    },
    
    organizeByType: Ember.computed.alias('pricingTypes.organizeByType'),
        
    pricingTypeList: function() {
        var pricingTypeValues = this.get('pricingTypeValues'),
            pricingTypeForObjectType = this.get('pricingTypeForObjectType');
        pricingTypeValues = pricingTypeValues.filter(function(pricingType) {
            return pricingType !== pricingTypeForObjectType;
        });
        return pricingTypeValues;
    }.property('pricingTypeValues','pricingTypeForObjectType'),
    
    pricingTypeValues: Ember.computed.alias('pricingTypes.value'),
    
    saveNewPricing: function(pricingName, pricingCategory, priceObjectToSet) {
        return new Ember.RSVP.Promise(function(resolve, reject) {
            var newPricing,
                pricingTypeForObjectType = this.get('pricingTypeForObjectType');
            newPricing = this.store.createRecord('pricing', {
                name: pricingName,
                category: pricingCategory,
                type: pricingTypeForObjectType
            });
            newPricing.save().then(function() {
                this.get('pricingList').addObject({
                    _id: 'pricing_'+ newPricing.get('id'),
                    name: newPricing.get('name')
                });
                this.set(priceObjectToSet, newPricing);
                resolve();
            }.bind(this), reject);
        }.bind(this), 'saveNewPricing for: '+pricingName);        
    },
       
    selectedObjectTypeChanged: function(selectedField, typeField) {
        var isNew = this.get('isNew'),
            selectedItem = this.get(selectedField);
        if (isNew) {
            if (!Ember.isEmpty(selectedItem)) {            
                this.store.find('pricing', selectedItem._id.substr(8)).then(function(item) {
                    this.set(typeField, item);
                }.bind(this));
            } else {
               this.set(typeField);
            }
        }
    },
  
    showAddCharge: function() {
        var canAddCharge = this.get('canAddCharge'), 
            organizeByType = this.get('organizeByType');
        if (canAddCharge) {
            return !organizeByType;
        } else {
            return false;
{'fraction_non_alphanumeric': 0.111591169918315, 'fraction_numerical': 0.0005400661581043678, 'mean_word_length': 1.9218934911242604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1977630', 'n_tokens_mistral': 3900, 'n_tokens_neox': 3802, 'n_words': 675}