<commit_before>import $ from 'jquery';
import '../../../utils/velocity';
import 'select2';
import _ from 'underscore';
import path from 'path';
import { MediumEditor } from 'medium-editor';
import { isScrolledIntoView } from '../../../utils/dom';
import { getCurrenciesSortedByCode } from '../../../data/currencies';
import { formatPrice } from '../../../utils/currency';
import SimpleMessage from '../SimpleMessage';
import loadTemplate from '../../../utils/loadTemplate';
import ShippingOptionMd from '../../../models/listing/ShippingOption';
import Service from '../../../models/listing/Service';
import Image from '../../../models/listing/Image';
import app from '../../../app';
import BaseModal from '../BaseModal';
import ShippingOption from './ShippingOption';

export default class extends BaseModal {
  constructor(options = {}) {
    if (!options.model) {
      throw new Error('Please provide a model.');
    }

    const opts = {
      removeOnClose: true,
      modelContentClass: 'modalContent clrP',
      ...options,
    };

    super(opts);
    this.options = opts;

    // So the passed in modal does not get any un-saved data,
    // we'll clone and update it on sync
    this._origModel = this.model;
    this.model = this._origModel.clone();
    this.listenTo(this.model, 'sync', () => {
      if (this.createMode && this.model.lastSyncedAttrs.listing &&
        this.model.lastSyncedAttrs.listing.slug) {
        this.createMode = false;
        this.$('.js-listingHeading').text(app.polyglot.t('editListing.editListingLabel'));
      }

      this._origModel.set(this.model.toJSON());

      // A change event won't fire on a parent model if only nested attributes change.
      // The nested models would need to have change events manually bound to them
      // which is cumbersome with a model like this with so many levels of nesting.
      // If you are interested in any change on the model (as opposed to a sepcific
      // attribute), the simplest thing to do is use the 'saved' event from the
      // event emitter in models/listing/index.js.
    });

    this.innerListing = this.model.get('listing');
    this.selectedNavTabIndex = 0;
    this.createMode = !(this.model.lastSyncedAttrs.listing &&
      this.model.lastSyncedAttrs.listing.slug);
    this.photoUploads = [];
    this.images = this.innerListing.get('item').get('images');
    this.shippingOptions = this.innerListing.get('shippingOptions');
    this.shippingOptionViews = [];

    loadTemplate('modals/editListing/uploadPhoto.html',
      uploadT => (this.uploadPhotoT = uploadT));

    this.listenTo(this.images, 'add', this.onAddImage);
    this.listenTo(this.images, 'remove', this.onRemoveImage);

    this.listenTo(this.shippingOptions, 'add', (shipOptMd) => {
      this.$('.js-sectionShipping').addClass('hasShippingOptions');
<commit_msg>updating create mode to be edit mode after a listing is created<commit_after>import $ from 'jquery';
import '../../../utils/velocity';
import 'select2';
import _ from 'underscore';
import path from 'path';
import { MediumEditor } from 'medium-editor';
import { isScrolledIntoView } from '../../../utils/dom';
import { getCurrenciesSortedByCode } from '../../../data/currencies';
import { formatPrice } from '../../../utils/currency';
import SimpleMessage from '../SimpleMessage';
import loadTemplate from '../../../utils/loadTemplate';
import ShippingOptionMd from '../../../models/listing/ShippingOption';
import Service from '../../../models/listing/Service';
import Image from '../../../models/listing/Image';
import app from '../../../app';
import BaseModal from '../BaseModal';
import ShippingOption from './ShippingOption';

export default class extends BaseModal {
  constructor(options = {}) {
    if (!options.model) {
      throw new Error('Please provide a model.');
    }

    const opts = {
      removeOnClose: true,
      modelContentClass: 'modalContent clrP',
      ...options,
    };

    super(opts);
    this.options = opts;

    // So the passed in modal does not get any un-saved data,
    // we'll clone and update it on sync
    this._origModel = this.model;
    this.model = this._origModel.clone();
    this.listenTo(this.model, 'sync', () => {
      setTimeout(() => {
        if (this.createMode && !this.model.isNew()) {
          this.createMode = false;
          this.$('.js-listingHeading').text(app.polyglot.t('editListing.editListingLabel'));
        }

        this._origModel.set(this.model.toJSON());
      });

      // A change event won't fire on a parent model if only nested attributes change.
      // The nested models would need to have change events manually bound to them
      // which is cumbersome with a model like this with so many levels of nesting.
      // If you are interested in any change on the model (as opposed to a sepcific
      // attribute), the simplest thing to do is use the 'saved' event from the
      // event emitter in models/listing/index.js.
    });

    this.innerListing = this.model.get('listing');
    this.selectedNavTabIndex = 0;
    this.createMode = !(this.model.lastSyncedAttrs.listing &&
      this.model.lastSyncedAttrs.listing.slug);
    this.photoUploads = [];
    this.images = this.innerListing.get('item').get('images');
    this.shippingOptions = this.innerListing.get('shippingOptions');
    this.shippingOptionViews = [];

    loadTemplate('modals/editListing/uploadPhoto.html',
      uploadT => (this.uploadPhotoT = uploadT));

    this.listenTo(this.images, 'add', this.onAddImage);
    this.listenTo(this.images, 'remove', this.onRemoveImage);

    this.listenTo(this.shippingOptions, 'add', (shipOptMd) => {
      this.$('.js-sectionShipping').addClass('hasShippingOptions');

{'fraction_non_alphanumeric': 0.1504455705049799, 'fraction_numerical': 0.0006989341254586755, 'mean_word_length': 3.079828937990021, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2546600', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1615, 'n_words': 449}