class BaseOperation(Executable):
    def __init__(self, trello_element, previous_operation=None):
        self.custom_actions = CustomActions(self)
        self.trello_element = trello_element
        self.previous_operation = previous_operation
        self.after_init()

    def after_init(self):
        pass

    def items(self):
        self.set_collection()
        return self.custom_actions.encapsulate(self.collection.names())

    def set_collection(self):
        self.collection = TrelloCollection(self.trello_element,
                                           self.trello_element_property())

    def trello_element_property(self):
        return ""

    def trello_element_name(self):
        return self.__class__.__name__.replace("Operation", "")

    def callback(self, index):
        if self.custom_actions.has(index):
            self.custom_actions.call(index)
        else:
            self.command.defer(lambda: self.execute_command(
                index - self.custom_actions.len()))

    def get_name(self, label="Name"):
        self.command.input(label, self.deferred_add)

    def deferred_add(self, text=None):
        if text:
            self.command.defer(lambda: self.base_add(text))

    def base_add(self, text):
        self.add(text)
        self.restart()

    def add(self, text):
        pass

    def restart(self):
        self.trello_element.reload()
        self.reexecute()

    def execute_command(self, index):
        if self.collection.has(index):
            Operation = self.next_operation_class()
            Operation(self.collection.find(index), self).execute(self.command)

    def next_operation_class(self):
        pass

    def open_in_browser(self):
        self.command.defer(super().open_in_browser)
class BaseOperation(Executable):
    def __init__(self, trello_element, previous_operation = None):
        self.custom_actions = CustomActions(self)
        self.trello_element = trello_element
        self.previous_operation = previous_operation
        self.after_init()

    def after_init(self):
        pass

    def items(self):
        self.set_collection()
        return self.custom_actions.encapsulate(self.collection.names())

    def set_collection(self):
        self.collection = TrelloCollection(self.trello_element, self.trello_element_property())

    def trello_element_property(self):
        return ""
        
    def trello_element_name(self):
        return self.__class__.__name__.replace("Operation", "")

    def callback(self, index):
        if self.custom_actions.has(index):
            self.custom_actions.call(index)
        else:
            self.command.defer(lambda: self.execute_command(index - self.custom_actions.len()))

    def get_name(self):
        self.command.input("Name", self.deferred_add)

    def deferred_add(self, text = None):
        if text:
            self.command.defer(lambda: self.base_add(text))

    def base_add(self, text):
        self.add(text)
        self.restart()

    def add(self, text):
        pass

    def restart(self):
        self.trello_element.reload()
        self.reexecute()

    def execute_command(self, index):
        if self.collection.has(index):
            Operation = self.next_operation_class()
            Operation(self.collection.find(index), self).execute(self.command)

    def next_operation_class(self):
        pass

    def open_in_browser(self):
        self.command.defer(super().open_in_browser)
 def __init__(self, trello_element, previous_operation = None):
     self.custom_actions = CustomActions(self)
     self.trello_element = trello_element
     self.previous_operation = previous_operation
     self.after_init()
 def __init__(self, trello_element, previous_operation=None):
     self.custom_actions = CustomActions(self)
     self.trello_element = trello_element
     self.previous_operation = previous_operation
     self.after_init()